Hello, could someone tell me how to avoid having negative values in silver? that is to say that sometimes I buy something, even if I don’t have the necessary money, it buys me the object and puts me a negative value, Can you help me please?
My script :
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local money = Instance.new("IntValue")
money.Name = "Money"
money.Value = 350
money.Parent = leaderstats
end)
I assume you want to make an – exchange of Money for Object – service, if that’s your case, you can check if your Player’s Money is greater or equal with
if Player.leaderstats.Money.Value >= Item.Price.Value then
--[[ TODO: give the Item and substract the Money ]]
Player.leaderstats.Money.Value -= Item.Price.Value
end
P.D.: @docega075 , if you are using a Client-Server Communication (e.g. RemoteEvent/BindableEvent/[. . .]) make a list of information per item (table); exploiters can manipulate your Event to share unexpected information (in this case, you will probably use replicated items as an argument for your events, and a exploiter can easily fake an Item with a table).