Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My debounce part of the script is not working?

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?

5 comments

0

you're not putting a wait before settings living back to true, so it's just true instantly.

0

But in line 9 i changed it to false and on 10 i put a wait(1) then later in 18 i set it back to true... But if this is still wrong can you answer with the corrected version of this?

0

you have to put the wait before setting it back to true.

0

I dont understand, can you send a corrected version?

0

I did.

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.