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

Math with Values?

Asked by 10 years ago

I am working on a paying script, and I am trying to make it so that it pays and takes the right amount of money every 5 seconds. I have 3 values, Giver, Getter and Amount. Is there a special way to do math with a value because this didn't work:

local giver = game.Players:FindFirstChild(script.Parent.Giver.Value)
local givermoney = giver.leaderstats.Tuncidunt.Value
local getter = game.Players:FindFirstChild(script.Parent.Getter.Value)
local gettermoney = getter.leaderstats.Tuncidunt.Value
local amount = script.Parent.Amount.Value
while true do
givermoney = givermoney - amount
gettermoney = gettermoney + amount
wait(5) 
end

Can anyone help?

1 answer

Log in to vote
0
Answered by
jobro13 980 Moderation Voter
10 years ago

Hey! I once got this issue too and it is really confusing.

What you should know here is that you are setting the ** variables ** givermoney and gettermoney and not their values! What you actually want is:

local giver = game.Players:FindFirstChild(script.Parent.Giver.Value)
local givermoney = giver.leaderstats.Tuncidunt.Value
local getter = game.Players:FindFirstChild(script.Parent.Getter.Value)
local gettermoney = getter.leaderstats.Tuncidunt.Value
local amount = script.Parent.Amount.Value
while true do
giver.leaderstats.Tuncidunt.Value = givermoney - amount
if game.Players:FindFirstChild(script.Parent.Getter.Value) then -- to make sure the script doesn't crash when the player leaves
    game.Players:FindFirstChild(script.Parent.Getter.Value).leaderstats.Tuncidunt.Value = gettermoney + amount
end
wait(5) 
end

Ad

Answer this question