Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My debounce part of the script is not working?

Asked by 4 years ago
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?

0
you're not putting a wait before settings living back to true, so it's just true instantly. killerbrenden 1537 — 4y
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? NathanTheCraziest 105 — 4y
0
you have to put the wait before setting it back to true. killerbrenden 1537 — 4y
0
I dont understand, can you send a corrected version? NathanTheCraziest 105 — 4y
0
I did. Geobloxia 251 — 4y

1 answer

Log in to vote
1
Answered by
Geobloxia 251 Moderation Voter
4 years ago
Edited 4 years ago

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)
Ad

Answer this question