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

Why is my Currency Notifier showing up as a Zero?

Asked by 4 years ago
Edited 4 years ago

Heyo, I was creating a lil' something, where everytime a player's currency, changes, a little notification will pop up saying the amount of currency that they have gotten. Well, I got into a small problem, (I think.) where it does not say how much currency they've gotten, but instead keep showing that they've gotten zero. It grab's the player's Cash, and subtract it by the amount of Cash they've gotten, I thought the output was, well the amount of Cash they received, I was wrong!

local player = game.Players.LocalPlayer

player.leaderstats:WaitForChild("Cash").Changed:Connect(function(amount)

    script.Parent:WaitForChild("cn_Sound"):Play()

    script.Parent:WaitForChild("cn_Label1"):TweenPosition(UDim2.new(0.8, 0, 0.48, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1)

    script.Parent:WaitForChild("cn_Label1").Text = "+"..player.leaderstats:WaitForChild("Cash").Value-amount.." Cash"

    wait(4)

    script.Parent:WaitForChild("cn_Label1"):TweenPosition(UDim2.new(1, 0, 0.48, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1)

end)

--keeps showing up as zero!!!

Please tell me why this occurs. ~unsnap

1 answer

Log in to vote
1
Answered by 4 years ago

The issue here is that in you're script it calls for the current amount. Which basically means when the script gets to the part to see how much you've gained, the cash was already added to your account and it's trying to subtract it from itself which in return gives you 0. You should add the cash AFTER the notification is over.

In short, you are asking the system to subtract the current cash from itself. Add the cash after the notification is over so there is a difference.

Ad

Answer this question