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

My value does not print " - " when i decrease value ?

Asked by 5 years ago
Edited 5 years ago

In the console when i decrease value it just showing the " + " Console : > game.Players.tommy2100.leaderstats.Money.Value = game.Players.tommy2100.leaderstats.Money.Value - 250 Note: I have create a LocalScript and put into StarterGui

local plr = game.Players.LocalPlayer

local stats = plr:WaitForChild("leaderstats")

local money = stats:WaitForChild("Money")

local gold = stats:WaitForChild("Gold")

local rs = game:GetService("ReplicatedStorage")

local sound = rs:WaitForChild("GetCash")

local sound2 = rs:WaitForChild("GetGold")



money.Changed:Connect(function()

if money.Value + money.Value then

print("+")

elseif money.Value - money.Value then

print("-")

end

end)



gold.Changed:Connect(function()

if gold.Value + gold.Value then

print("+")

elseif gold.Value - gold.Value then

print("-")

end

end)
0
This's the exact same thing as doing `5 + 5`; you're adding and subtracting a number, which will return a result (5 + 5 = 10, so 10 will return), so it's going to do `if 10 then`. The solution's to keep a variable of the last number and compare it. TheeDeathCaster 2368 — 5y
0
Use gold:GetPropertyChangedSignal("Value"):Connect(function() end) namespace25 594 — 5y

1 answer

Log in to vote
0
Answered by
ben0h555 417 Moderation Voter
5 years ago

That isnt how 'if statements' work, when you put

if xyz - xyz then dostuff() end

It subtracts xyz from xyz and then checks if that isnt false or nil, if it isnt false or nil then it passes the 'if statement'. So it immeaditly goes through the first 'if statement' and never reaches the elseif.

Instead you should check how the value has changed since it was last set.

xyz1 = 0
xyz2 = xyz1
xyz1 = xyz1 + 1
if xyz1 > xyz2 then
    print("Value is higher!")
elseif xyz1 < xyz2 then
    print("Value is lower")
end
Ad

Answer this question