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

How to take value from leaderboard and refrain from negative value?

Asked by 3 years ago

Working on a type of tycoon game, need money (value) to be taken from player leaderboard without putting the player at a negative value. X = 1000 to purchase, X has 100, script allows for user to purchase anyway but puts player at -900 value. Here's what I have so far, value is set for -1000 and i imagine that's the cause of the error. Asking first but looking through SH questions to see if this hasn't been answered before.

amount = script.Parent.MoneyValue.Value
wait_time = 10   
x = script.Parent
enabled = true

function touch(hit)
if not enabled then return end
enabled = false
local h = hit.Parent:findFirstChild("Humanoid")
if h ~= nil then
local p = game.Players:getPlayerFromCharacter(hit.Parent)
local money = p.leaderstats.Money
if p.TeamColor ~= BrickColor.new("Bright green") then
money.Value = money.Value + amount
script.Parent.MoneyValue.Value = 0
p.TeamColor = BrickColor.new("Bright green")
x.Parent.Name = "Finished!"
wait(wait_time)
x.Parent.Name = "Complete Training: 1000"
enabled = true
end
end
end

x.Touched:connect(touch)

Question is, how would I modify my script to take away 1000? Would I add a function if p.leaderstats.Money = <1000 then end somewhere in the lines? I imagine, I can change

...
money.Value = money.Value - amount
script.Parent.MoneyValue.Value = 1000

Answer this question