Timed Obby Start and Finish Gates thumbnail
0 views0 copies0 likes

Timed Obby Start and Finish Gates

Universal script

Copy it, then test it in your own Studio place.

Utilities Verified

Script code

25 lines · 1.0 KB
Download
local Players = game:GetService("Players")local starts = {}local function owner(hit)	local character = hit:FindFirstAncestorOfClass("Model")	return character and Players:GetPlayerFromCharacter(character)endlocal function bind(player)	player.CharacterAdded:Connect(function() starts[player] = nil end)endPlayers.PlayerAdded:Connect(bind)Players.PlayerRemoving:Connect(function(player) starts[player] = nil end)workspace:WaitForChild("RaceStart").Touched:Connect(function(hit)	local player = owner(hit)	if player and not starts[player] then starts[player] = workspace:GetServerTimeNow() end-- …open Get script for the full source

About this script

Create two anchored parts called RaceStart and RaceFinish in Workspace. Touching the start records server time for that player, and touching the finish ends the run and updates the player's personal best when appropriate. Both times are attributes so a race UI can display them later. Resetting the avatar cancels the active run. Test two players finishing in different orders.

Comments

Share what works, ask questions, or report an issue.

0

Log in to leave a comment.

No comments yet

Be the first to share your thoughts!

Raw Luau source

local Players = game:GetService("Players")
local starts = {}
local function owner(hit)
	local character = hit:FindFirstAncestorOfClass("Model")
	return character and Players:GetPlayerFromCharacter(character)
end
local function bind(player)
	player.CharacterAdded:Connect(function() starts[player] = nil end)
end
Players.PlayerAdded:Connect(bind)
Players.PlayerRemoving:Connect(function(player) starts[player] = nil end)
workspace:WaitForChild("RaceStart").Touched:Connect(function(hit)
	local player = owner(hit)
	if player and not starts[player] then starts[player] = workspace:GetServerTimeNow() end
end)
workspace:WaitForChild("RaceFinish").Touched:Connect(function(hit)
	local player = owner(hit)
	local began = player and starts[player]
	if not began then return end
	starts[player] = nil
	local duration = workspace:GetServerTimeNow() - began
	player:SetAttribute("LastRaceSeconds", duration)
	local best = player:GetAttribute("BestRaceSeconds")
	if not best or duration < best then player:SetAttribute("BestRaceSeconds", duration) end
end)