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

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

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

✓ Accepted answer

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

1 comment

0

Thank you very much! You don't know how much I appreciated it! Good luck with your games too!

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