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

Script Quits Functioning, But Then Wont Function Again, Help!?

Asked by 5 years ago

My script is supposed to work where, if the player gets under -$2, the script "quits functioning" (for lack of a better word). If the player goes below -$2, then back above it, the script quits working. My intentions are so that when below -$2 it quits, when above -$2, it starts functioning again. It doesn't and I don't know why, please help!

moneyToGive = -100
debounce = false
script.Parent.Touched:connect(function(hit)
    if debounce == true then return end
    player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player == nil then return end
    stat = player:findFirstChild("leaderstats")
    if stat == nil then return end
    cash = stat:findFirstChild("Cash")
    if cash == nil then return end
    debounce = true
    if cash.Value <= -2 then
        script.Sound2:Play()
    end
    if cash.Value >= -1 then
        cash.Value = cash.Value + moneyToGive
        game.Workspace.Tug.Body.Concrete.Transparency = 0
        game.Workspace.Tug.Body.Straps.Transparency = 0
        script.Sound:Play()
        game.Workspace.Tug.Body.Cash100l.BillboardGui.Enabled = true
        wait(3.5)
        game.Workspace.Tug.Body.Cash100l.BillboardGui.Enabled = false
        wait(2)
        debounce = false
    end
end)

1 answer

Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
5 years ago

Hello, Darkcraft10!

I think you just forgot to disable debounce...

moneyToGive = -100
debounce = false
script.Parent.Touched:connect(function(hit)
    if debounce == true then return end
    player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player == nil then return end
    stat = player:findFirstChild("leaderstats")
    if stat == nil then return end
    cash = stat:findFirstChild("Cash")
    if cash == nil then return end
    debounce = true
    if cash.Value <= -2 then
        script.Sound2:Play()
    wait(2)
    debounce = false --Forgot to disable debounce here
    end
    if cash.Value >= -1 then
        cash.Value = cash.Value + moneyToGive
        game.Workspace.Tug.Body.Concrete.Transparency = 0
        game.Workspace.Tug.Body.Straps.Transparency = 0
        script.Sound:Play()
        game.Workspace.Tug.Body.Cash100l.BillboardGui.Enabled = true
        wait(3.5)
        game.Workspace.Tug.Body.Cash100l.BillboardGui.Enabled = false
        wait(2)
        debounce = false
    end
end)

Good Luck with your games

0
Thank you very much! You don't know how much I appreciated it! Good luck with your games too! Darkcraft10 20 — 5y
Ad

Answer this question