local living = true -- This is what I use for the debounce script.Parent.Touched:Connect(function(hit) if living == true then -- Since it's true this part will run local Player = game.Players[hit.Parent.Name] local frame = Player.PlayerGui.DeathGui.Frame local Countdown = frame.Countdown if Player.Backpack.Lives.Value > 0 then -- The Lives value was set to 4 living = false -- But It does not change living to false wait(1) Player:LoadCharacter() local getSpawns = workspace.Start:GetChildren() local Spawn = getSpawns[math.random(1, #getSpawns)] workspace[Player.Name]:MoveTo(Spawn.Position) Player.Backpack.Lives.Value = Player.Backpack.Lives.Value - 1 Player.Backpack.Playing.Value = true living = true else local timeleft = 10 frame:TweenPosition(UDim2.new(0.5,0,0.5,0)) for v = 1, 10 do timeleft = timeleft - 1 Countdown.Text = timeleft wait(1) end end end end)
How to fix this?
This is what Killerbrenden was trying to say:
local living = true -- This is what I use for the debounce local time = 2 -- change it if you want -- time is the amount of time before living = true again script.Parent.Touched:Connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then -- checks if it is a player that touched it if living == true then -- Since it's true this part will run local Player = game.Players:GetPlayerFromCharacter(hit.Parent) -- that is a better way of getting player for this case local frame = Player.PlayerGui.DeathGui.Frame local Countdown = frame.Countdown if Player.Backpack.Lives.Value > 0 then living = false -- got rid of this line because it has to be directly before -- living = true. Player:LoadCharacter() local getSpawns = workspace.Start:GetChildren() local Spawn = getSpawns[math.random(1, #getSpawns)] workspace[Player.Name]:MoveTo(Spawn.Position) Player.Backpack.Lives.Value = Player.Backpack.Lives.Value - 1 Player.Backpack.Playing.Value = true wait(time) -- so it doesn't set it back instantly living = true else local timeleft = 10 frame:TweenPosition(UDim2.new(0.5,0,0.5,0)) for v = 1, 10 do timeleft = timeleft - 1 Countdown.Text = timeleft wait(1) end end end end end)