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

How do you subtract from a Current Value?

Asked by
PixelYT 30
9 years ago

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

0
Please... PixelYT 30 — 9y
0
About to post, hold on. Stupid wait limit... Muoshuu 580 — 9y
0
Post what 'value' is, in script form. killerkill29 35 — 9y

2 answers

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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.

Ad
Log in to vote
0
Answered by
Muoshuu 580 Moderation Voter
9 years ago

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

Answer this question