Trying to make a timed obby

So i was trying to make an obby where when you hit the start part the timer would pop up on your screen and start counting up. Once you reached the end part, it would tp you back to the main area. Instead what happens is when you hit the start part the timer doesnt show up on your screen and the tp doesnt work.

Here is the obby timer code:
local start = game.Workspace.ObbyStart
local stop = game.Workspace.ObbyEnd

local timerPart = game.StarterGui.ObbyTimer
local timerText = game.StarterGui.ObbyTimer.TextLabel

local timerDuration = 0
local timerActive = false

local ObbyMechanics = game.Workspace.ObbyStart.ObbyMechanics

local Completed = game.Workspace.ObbyStart.ObbyMechanics:GetAttribute(‘Completed’)

local count = 0

timerPart.Enabled = false

local ligma = false

local function startTimer()
print(“Timer started”)
timerActive = true
timerPart.Enabled = true
timerText.Enabled = true

while Completed == false do
	count += 1 
	timerText.Text = count
	wait(1)
end

end
if ligma == true then
local function obbyDone(stopTimer)
local character = stopTimer.Parent
local humanoid = character:FindFirstChildWhichIsA(“Humanoid”)
print(“attempting to tp”)

if humanoid and timerActive == true then 
	print("made it to get attribute")
	ObbyMechanics:GetAttribute('Completed')
	ObbyMechanics:SetAttribute('Completed', true)
	timerText.Text = "Final score: "..timerDuration
	wait(2)
	timerActive = false
	timerPart.Enabled = false
	ObbyMechanics:SetAttribute('Completed', false)	
	end	
end

end

local function buttonPressed(partTouched)
local character = partTouched.Parent
local humanoid = character:FindFirstChildWhichIsA(“Humanoid”)
print(“part touched”)

if humanoid and timerActive == false then
	print("starting timer")
	startTimer()
end

end

local function stopPressed(partTouched)
local character = partTouched.Parent
local humanoid = character:FindFirstChildWhichIsA(“Humanoid”)
print(“end touched”)

if humanoid and timerActive == true then
	print("ending timer")
	ligma = true
end

end

start.Touched:Connect(buttonPressed)

stop.Touched:Connect(stopPressed)

And this is the tp code:
local TeleportPart1 = script.Parent.TeleportPart1
local TeleportPart2 = script.Parent.TeleportPart2
local Completed = game.Workspace.ObbyStart.ObbyMechanics:GetAttribute(‘Completed’)

if Completed == true then
TeleportPart1.Touched:Connect(function(hit)
local w = hit.Parent:FindFirstChild(“HumanoidRootPart”)
print(“about to tp”)
if w then
w.CFrame = TeleportPart2.CFrame + Vector3.new(0, 5, 0)
TeleportPart2.CanTouch = false
wait(1)
TeleportPart2.CanTouch = true
print(“tp done”)
end
end)
end

Any help is appreciated! Thank you for your time.

1 Like

Anyone know? aaaaaaaaaaaaaaaaaaa

1 Like

For the gui, you are accessing the startergui which is different from what youre probably expecting. You will find the clients gui in Player.PlayerGui

When its going to teleport back, is the “print(“attemtping to tp”)” line printing in console

2 Likes

not really sure what’s going on with your code but the first script should be a LocalScript that’s inside the timer (unless you want to use RemoteEvents, or change the GUI from the server), and instead of making the gui enabled/disabled you could toggle the timer’s visibility

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local TimerGUI = Player.PlayerGui:WaitForChild("ObbyTimer") -- assuming this is the gui
local Timer = TimerGUI:WaitForChild("Timer") -- rename your stuff
-- learn to wait for stuff to load, otherwise it'll error for laggy players
local ObbyStart = workspace:WaitForChild("ObbyStart")
local ObbyStop = workspace:WaitForChild("ObbyEnd")

local ObbyMechanics = ObbyStart:WaitForChild("ObbyMechanics") -- use variables
local Completed = ObbyMechanics:GetAttribute("Completed")
-- timerDuration isn't needed since you're using count
timerActive = false
count = 0

local function startTimer(hit) -- name stuff properly
    -- you don't have to make a variable for hit.parent character if you're never using it again
	if hit.Parent == Character and not timerActive then
		print("Starting timer...")
		timerActive = true
		Timer.Visible = true
		while not Completed do
			count += 1 
			Timer.Text = count
			wait(1)
		end
	end
end

local function obbyDone(hit)
	print("Attempting to teleport player.") -- prints should make more sense
	if hit.Parent == Character and timerActive then
		ObbyMechanics:SetAttribute('Completed', true)
		Timer.Text = "Final score: " .. Timer.Text
		wait(5) -- give player time to read score
		timerActive = false
		Timer.Visible = false
		ObbyMechanics:SetAttribute('Completed', false)	
	end	
end

-- you only need startTimer, and obbyDone
ObbyStart.Touched:Connect(startTimer)
ObbyStop.Touched:Connect(obbyDone)

i’m assuimg the second script is a ServerScript that’s inside a ‘Teleport’ model

local ObbyMechanics = workspace:WaitForChild("ObbyStart"):WaitForChild("ObbyMechanics")

-- better names
local TeleportPart = script.Parent.TeleportPart1
local TeleportTarget = script.Parent.TeleportPart2

TeleportPart.Touched:Connect(function(hit)
    local Completed = ObbyMechanics:GetAttribute("Completed")

	if not Completed then return end
	local HRP = hit.Parent:FindFirstChild("HumanoidRootPart")
	
	if HRP then -- not sure what 'w' means
		-- you could position the 'TeleportPart2' properly
		HRP.CFrame = TeleportTarget.CFrame
		print("Teleported")
	end
end)
1 Like

It at least shows a time now, but the teleport doesnt work and if you hit the start part multiple times it also counts those (e.g. I accidently hit it twice so its counting by 2 now) and it also keeps counting when you hit the end part (but it resets when you die)

I fixed the hitting it multiple times problem, but it doesnt teleport you when you hit the end part nor stop counting until the 5 second wait for the final score (which only shows for one second because it keeps counting) is up

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.