Hello, I was making a shop for my game. And I was wondering how to subtract from the values when an item is bought.
Here is the script I was trying.
image.MouseButton1Down:connect(function() if value > 25 then local ball = game.ReplicatedStorage.Superball:Clone() ball.Parent = game.StarterPack ball.Parent = game.Players.Player.Backpack wait (0.5) game.Players.Player.leaderstats.Pixels.Value = value -25
This script gives a superball to the player when he buys the item, and the value of "Pixels" goes down 25 to 75 (originally 100). But when I "bought" another item for 10 Pixels the value goes to 90.
Also "value" is a variable for game.Players.Player.leaderstats.Pixels.Value
Please Help
Reading your post, it looks like you have value
set to the instantaneous value of that leaderstat, instead of the leaderstat itself.
Remove the .Value
part where you define value
, and replace line 7 in the above with value.Value = value.Value - 25
.
To subtract a value, you'd need to set it to it's current value subtracted by X, where X is the amount you are subtracting from it.
For instance, Value = Value - 25