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

Touch Money Losses Restricted?

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
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)
0
All you did was coppy my script... Darkcraft10 20 — 5y
0
no i added a if cash.Value >= 25 then MageMasterHD 261 — 5y
0
So you did, I missed that, my apologies. Thank you! Darkcraft10 20 — 5y
0
Np MageMasterHD 261 — 5y
Ad

Answer this question