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

Touch Money Losses Restricted?

I have a script, where when a brick is touched you lose money. I would like to make it so that if you don't have over 25 money, you wont lose any. So its like buying something but if you don't have enough, you can't. Anyway, I don't know where to go from here, any help? (Sorry I struggled with the title)

moneyToGive = -25

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
cash.Value = cash.Value + moneyToGive
wait(2)
debounce = false
end)

1 answer

✓ Accepted answer
moneyToGive = -25

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 >= 25 then --That may have to be if cash.Value <= 25 then
cash.Value = cash.Value + moneyToGive
wait(2)
debounce = false
end
end)

4 comments

0

All you did was coppy my script...

0

no i added a if cash.Value >= 25 then

0

So you did, I missed that, my apologies. Thank you!

0

Np

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