Hi, i am trying to make an obby where you have 3-4 attempts but if you use all your attempts you have to wait 2 minutes, i am using os.clock() so i can use Minute:Seconds format, problem is i dont know anything about it.
I have 3 issues,
Multiple surfaceGuis cloning into playerGui – there should be 1, there is 3
At the end, it starts going to the negative
I don’t know how to disconnect renderstepped
(if there is a more efficient way to do this; You are more than welcome to share)
Code:
--//Variables
local Counter = 0
local ObbySpawn = workspace.Spawns:WaitForChild("ObbySpawner")
local ObbyBlock = workspace:WaitForChild("Map"):WaitForChild("ObbyBlocker")
local Part = script.Parent
local DefaultSpawnLocation = workspace:WaitForChild("Spawns"):WaitForChild("DefaultSpawnLocation")
local SurfaceGui = script:WaitForChild("SurfaceGui")
local plr = game:GetService("Players").LocalPlayer
local plrGui = plr:WaitForChild("PlayerGui")
local deadline = os.clock() + 120 -- 2 Minutes
local debounce = false
--//Functions
function UpdateTimer()
local TimerLabel = plrGui:WaitForChild("Timer").TextLabel
local timerFormat = "%d:%d" -- As long it has the "%d", it will be possible to replace them with numbers.
-- Assuming this is inside of a BindToRenderStep or Updater.
local remaining = deadline - os.clock()
local m = math.floor(remaining/60) -- Minutes
local s = math.floor(remaining%60) -- Seconds -- Milliseconds
TimerLabel.Text = "Retry in: " .. string.format(timerFormat,m,s)
end
function onTouched(Hit)
if debounce == false then
debounce = true
if Hit.Parent:FindFirstChild("Humanoid") then
local Char = Hit.Parent
if Counter <= 3 then
Char:MoveTo(ObbySpawn.Position + Vector3.new(0,5,0))
Counter += 1
elseif Counter > 3 then
Char:MoveTo(DefaultSpawnLocation.Position + Vector3.new(0,5,0))
ObbyBlock.Transparency = 0.5
ObbyBlock.CanCollide = true
local SurfaceGuiClone = SurfaceGui:Clone()
SurfaceGuiClone.Name = "Timer"
SurfaceGuiClone.Parent = plrGui
SurfaceGuiClone.Adornee = ObbyBlock
game:GetService("RunService").RenderStepped:Connect(UpdateTimer) -- Connect to RenderStepped so we can update every frame.
task.wait(120)
--disconnect renderstepped
-- I DONT KNOW HOW
--destroy gui
SurfaceGuiClone:Destroy()
ObbyBlock.Transparency = 1
ObbyBlock.CanCollide = false
Counter = 0
end
end
end
Part.Touched:Connect(onTouched)
--//Variables
local Counter = 0
local ObbySpawn = workspace.Spawns:WaitForChild("ObbySpawner")
local ObbyBlock = workspace:WaitForChild("Map"):WaitForChild("ObbyBlocker")
local Part = script.Parent
local DefaultSpawnLocation = workspace:WaitForChild("Spawns"):WaitForChild("DefaultSpawnLocation")
local connection
local SurfaceGui = script:WaitForChild("SurfaceGui")
local plr = game:GetService("Players").LocalPlayer
local plrGui = plr:WaitForChild("PlayerGui")
local deadline = os.clock() + 120 -- 2 Minutes
local debounce = false
--//Functions
function UpdateTimer()
local TimerLabel = plrGui:WaitForChild("Timer").TextLabel
local timerFormat = "%d:%d" -- As long it has the "%d", it will be possible to replace them with numbers.
-- Assuming this is inside of a BindToRenderStep or Updater.
local remaining = deadline - os.clock()
local m = math.floor(remaining/60) -- Minutes
local s = math.floor(remaining%60) -- Seconds -- Milliseconds
TimerLabel.Text = "Retry in: " .. string.format(timerFormat,m,s)
end
function onTouched(Hit)
if debounce == false then
debounce = true
if Hit.Parent:FindFirstChild("Humanoid") then
local Char = Hit.Parent
if Counter <= 3 then
Char:MoveTo(ObbySpawn.Position + Vector3.new(0,5,0))
Counter += 1
elseif Counter > 3 then
Char:MoveTo(DefaultSpawnLocation.Position + Vector3.new(0,5,0))
ObbyBlock.Transparency = 0.5
ObbyBlock.CanCollide = true
local SurfaceGuiClone = SurfaceGui:Clone()
SurfaceGuiClone.Name = "Timer"
SurfaceGuiClone.Parent = plrGui
SurfaceGuiClone.Adornee = ObbyBlock
connection = game:GetService("RunService").RenderStepped:Connect(UpdateTimer) -- Connect to RenderStepped so we can update every frame.
task.wait(120)
--disconnect renderstepped
connection:Disconnect()
--destroy gui
SurfaceGuiClone:Destroy()
ObbyBlock.Transparency = 1
ObbyBlock.CanCollide = false
Counter = 0
end
task.wait()
debounce = false
end
end
if Hit.Parent:FindFirstChild("Humanoid") then
local Char = Hit.Parent
if Counter <= 3 then
Char:MoveTo(ObbySpawn.Position + Vector3.new(0,5,0))
Counter += 1
elseif Counter > 3 then
Char:MoveTo(DefaultSpawnLocation.Position + Vector3.new(0,5,0))
ObbyBlock.Transparency = 0.5
ObbyBlock.CanCollide = true
local SurfaceGuiClone = SurfaceGui:Clone()
SurfaceGuiClone.Name = "Timer"
SurfaceGuiClone.Parent = plrGui
SurfaceGuiClone.Adornee = ObbyBlock
game:GetService("RunService").RenderStepped:Connect(UpdateTimer) -- Connect to RenderStepped so we can update every frame.
task.wait(120)
--disconnect renderstepped
-- I DONT KNOW HOW
--destroy gui
SurfaceGuiClone:Destroy()
ObbyBlock.Transparency = 1
ObbyBlock.CanCollide = false
Counter = 0
end
end
end
Part.Touched:Connect(onTouched)
As you can see, I putted a connection. The connection was nil at first but then we have made connection a “RBXSignalConnection”. Then we can just put “:Disconnect”
function UpdateTimer()
local TimerLabel = plrGui:WaitForChild("Timer").TextLabel
local timerFormat = "%d:%d" -- As long it has the "%d", it will be possible to replace them with numbers.
-- Assuming this is inside of a BindToRenderStep or Updater.
local remaining = deadline - os.clock()
local m = math.floor(remaining/60) -- Minutes
local s = math.floor(remaining%60) -- Seconds -- Milliseconds
TimerLabel.Text = "Retry in: " .. string.format(timerFormat,m,s)
end