Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Number value changed? (new value - past value)

simple little script but all it does is put out how much money i currently have. so if it add 15 to 10 lets say, its says i added 25, when i only added 15...

local rs = game:GetService("ReplicatedStorage")
local animation = rs:WaitForChild("moneyAnimation")


game.Players.PlayerAdded:Connect(function(plr)
	local money = rs:WaitForChild("LockedBanks"):WaitForChild(plr.Name)
	
	
	while wait() do
		local pastMoney = money.Value
		
		money.Changed:Connect(function(newMoney)
			if newMoney > pastMoney then 
				animation:FireClient(plr, newMoney - pastMoney)
				wait(2)
			end
		end)
	end 
end)

1 answer

✓ Accepted answer

Event-driven is better than loops, plus why use an event and a loop?

local pastMoney = money.Value

money.Changed:Connect(function(newMoney)
    animation:FireClient(plr, newMoney - pastMoney)
    pastMoney = newMoney
end)

4 comments

0

i tried that but it does the same thing because the starting value was 0. Thats why i added the loop so itll get the most recent value before the change

0

Use the argument passed which is the new value ;~;

0

Try waiting a few seconds before the pastMoney value is set to change the initial value

0

thank you

This discussion is preserved as it was. New answers, comments, and votes are closed.