GUI Not Displaying Correct Deducted Currency Value

Hello.
I just had an issue with purchasing a new area that I had a bit of help fixing, now after that, it seems to be messing with a GUI I have that displays when a certain amount of coins is added to the players leaderstats, or is taken away. For this issue, it is being taken away. When the area is purchased, the correct amount is taken away but instead of displaying “-12500” it was displaying that over 100,000 coins were taken.

Here is the new script I am currently using from @BabyNinjaTime

local Players = game:GetService("Players")
local plr = Players.LocalPlayer

local leaderstats = plr:WaitForChild("leaderstats")
local CoinsValue = leaderstats:WaitForChild("Coins")

CoinsValue.Changed:Connect(function()
	local text = script.Parent.PopUp.TextLabel:Clone()
	text.Parent = script.Parent.PopUp
	text.Name = "+"..CoinsValue.Name
	text.Text = "+".. tostring(CoinsValue.Value)
	text.Rotation = math.random(-20,20)
	text.Visible = true
	local pos = UDim2.new(math.random(0,1000)/1000, 0,0.924, 0)
	text.Position = pos
	text:TweenPosition(pos-UDim2.new(0,0,1,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,1)
	wait(1)
	text:Destroy()
end)

If someone could help that would be great!

I thought this code was to display how many coins a person has, but I just realized that this code is to make a pop up message of how much coins were added or taken away.

I believe this code should fix your issue:

local Players = game:GetService("Players")
local plr = Players.LocalPlayer

local leaderstats = plr:WaitForChild("leaderstats")
local CoinsValue = leaderstats:WaitForChild("Coins")
local CurrentValue = CoinsValue.Value

CoinsValue.Changed:Connect(function()
	local text = script.Parent.PopUp.TextLabel:Clone()
	text.Parent = script.Parent.PopUp
	
	if CoinsValue.Value < CurrentValue then
		text.Name = "-".. tostring(CurrentValue - CoinsValue.Value)
		text.Text = "-".. tostring(CurrentValue - CoinsValue.Value)
		
	elseif CoinsValue.Value > CurrentValue then
		text.Name = "+".. tostring(CoinsValue.Value - CurrentValue)
		text.Text = "+".. tostring(CoinsValue.Value - CurrentValue)
	end
	
	text.Rotation = math.random(-20,20)
	text.Visible = true
	local pos = UDim2.new(math.random(0,1000)/1000, 0,0.924, 0)
	text.Position = pos
	text:TweenPosition(pos-UDim2.new(0,0,1,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,1)
	wait(1)
	CurrentValue = CoinsValue.Value
	text:Destroy()
end)

Yes, that worked! Thanks a lot for your help, and sorry for the confusion haha.

1 Like

You are welcome, glad it works now! Happy to help!

1 Like