How can I fix this Coin GUI Script

Hello! How can I make this so it shows the GUI for when you collect Coins, no matter what if you collect that stat. How can I do that? My current one for some reason, only shows it if you get a higher value then you had. Lets say you had 100 Coins, you sell them, then collect a Coin, it would not show up, but if you got back to 100, then got to 101 Coins then it’ll show up, etc, etc. How can I fix this?

Example Video:

My current script:

local suffixes = {'','K','M','B','T','qd','Qn','sx','Sp','O','N','de','Ud','DD','tdD','qdD','QnD','sxD','SpD','OcD','NvD','Vgn','UVg','DVg','TVg','qtV','QnV','SeV','SPG','OVG','NVG','TGN','UTG','DTG','tsTG','qtTG','QnTG','ssTG','SpTG','OcTG','NoAG','UnAG','DuAG','TeAG','QdAG','QnAG','SxAG','SpAG','OcAG','NvAG','CT'}
local function format(val)
	for i=1, #suffixes do
		if tonumber(val) < 10^(i*3) then
			return math.floor(val/((10^((i-1)*3))/100))/(100)..suffixes[i]
		end
	end
end

local Player = game.Players.LocalPlayer
script.Parent.Visible = true 
local Stats = Player:WaitForChild("leaderstats")
local Cash = Stats:WaitForChild ("Coins")
repeat
	wait(0.01)
	script.Parent.Text =  (format(Cash.Value)),"Out","Linear"
	
until script.Disabled == true

If that is not it, here is the script for the +Coins GUI Which is the script that makes it show up

local Players = game:GetService("Players")
local plr = script.Parent.Parent.Parent
local leaderstats = plr:WaitForChild("leaderstats")
local cash = leaderstats:WaitForChild("Coins")

local dif = 0
delay(.25, function()
    dif = cash.Value
end)

cash.Changed:Connect(function()
	if dif ~= cash.Value and dif <= cash.Value then
		local random = math.random(1, 900)
		local xnew = random / 1000
		local new = script:WaitForChild("Coins"):Clone()
		new:WaitForChild("CoinsInfo").Text = "+".. cash.Value - dif
		new.Position = UDim2.new(xnew, 0, 1, 0)
		new.Parent = script.Parent
		dif = cash.Value
		wait(0.1)
		new:TweenPosition(UDim2.new(new.Position.X, 0, -0.1, 0))
		wait(2)
		new.Parent = nil
	end
end)

Any help will be appreciated! :grinning_face_with_smiling_eyes:

If anyone knows why it is happening, it’ll be appreciated!

This is because in your first script, you said that you will only run the +Coin GUI script IF the dif variable is less than the cash value. Let’s say that you picked up a coin. When the code runs, the dif variable will be changed to 1. But now when you sell the coin, since the dif variable will now be greater than your cash value (which is now 0), the code will not run and the dif variable will be stuck as 1. I hope this helps you identify the problem!

3 Likes

Sorry it took so long to respond, I’ve been busy doing something else!

Is the problem inside this part?

local Player = game.Players.LocalPlayer
script.Parent.Visible = true 
local Stats = Player:WaitForChild("leaderstats")
local Cash = Stats:WaitForChild ("Coins")
repeat
	wait(0.01)
	script.Parent.Text =  (format(Cash.Value)),"Out","Linear"
	
until script.Disabled == true

I see to have an error thingy on the (I assume this means nothing)

Script.Parent.Text = (format(Cash.Value)),"Out","Linear"

It basically means you are trying to set script.Parent’s text to 3 values: format(Cash.Value), β€œOut”, and β€œLinear”. Try putting the 3 of them in parentheses.

Something like this?

local Cash = Stats:WaitForChild ("Coins")
repeat
	wait(0.01)
	script.Parent.Text =  (format(Cash.Value))("Out","Linear")
	
until script.Disabled == true
1 Like

Instead of using cash.Changed, you should just have a loop instead. Also, when you sell the coin, your game.Players.LocalPlayer.leaderstats.Coins.Value turns to 0 but the variable dif does not since dif is larger than game.Players.LocalPlayer.leaderstats.Coins.Value. So, this script will definitely work.

local dif = game.Players.LocalPlayer.leaderstats.Coins.Value
while wait() do
	if dif ~= game.Players.LocalPlayer.leaderstats.Coins.Value then
        local dif2 = game.Players.LocalPlayer.leaderstats.Coins.Value - dif
        dif = game.Players.LocalPlayer.leaderstats.Coins.Value
	    if dif2 > 0 then
            local random = math.random(1, 900)
	    	local xnew = random / 1000
	    	local new = script.Coins:Clone()
	    	newCoinsInfo.Text = "+".. game.Players.LocalPlayer.leaderstats.Coins.Value - dif
	    	new.Position = UDim2.new(xnew, 0, 1, 0)
	    	new.Parent = script.Parent
	    	wait(0.1)
	    	new:TweenPosition(UDim2.new(new.Position.X, 0, -0.1, 0))
	    	wait(2)
	    	new.Parent:Destroy()
        end
	end
end

If it worked, it would be appreciated to have this set as solution :slight_smile: Have a great day/night!

Do I need to change anything inside the script? Or leave it as it is.

You should change this local script:

local Players = game:GetService("Players")
local plr = script.Parent.Parent.Parent
local leaderstats = plr:WaitForChild("leaderstats")
local cash = leaderstats:WaitForChild("Coins")

local dif = 0
delay(.25, function()
    dif = cash.Value
end)

cash.Changed:Connect(function()
	if dif ~= cash.Value and dif <= cash.Value then
		local random = math.random(1, 900)
		local xnew = random / 1000
		local new = script:WaitForChild("Coins"):Clone()
		new:WaitForChild("CoinsInfo").Text = "+".. cash.Value - dif
		new.Position = UDim2.new(xnew, 0, 1, 0)
		new.Parent = script.Parent
		dif = cash.Value
		wait(0.1)
		new:TweenPosition(UDim2.new(new.Position.X, 0, -0.1, 0))
		wait(2)
		new.Parent = nil
	end
end)

Into this local script:

local dif = game.Players.LocalPlayer.leaderstats.Coins.Value
while wait() do
	if dif ~= game.Players.LocalPlayer.leaderstats.Coins.Value then
        local dif2 = game.Players.LocalPlayer.leaderstats.Coins.Value - dif
        dif = game.Players.LocalPlayer.leaderstats.Coins.Value
	    if dif2 > 0 and script:FindFirstChild("Coins") then
            local random = math.random(1, 900)
	    	local xnew = random / 1000
	    	local new = script.Coins:Clone()
	    	new.CoinsInfo.Text = "+".. game.Players.LocalPlayer.leaderstats.Coins.Value - dif
	    	new.Position = UDim2.new(xnew, 0, 1, 0)
	    	new.Parent = script.Parent
	    	wait(0.1)
	    	new:TweenPosition(UDim2.new(new.Position.X, 0, -0.1, 0))
	    	wait(2)
	    	new.Parent:Destroy()
        end
	end
end

If it worked, it would be appreciated to have this set as solution :slight_smile: Have a great day/night!

this would work but i would also recommend using task.wait() because it is way more efficient than wait()

This doesn’t seem to work? I am getting this error. But Roblox is breaking right now, so none of my data stuff seems to work currently and I am getting aton of errors. But besides that, I get this error.

Right now, roblox seems to have an issue. You can’t log in if you log out, and if you go to the roblox’s page, you will see an error message. We have to wait for roblox to fix this problem.

Alright, well Ima head to bed and we’ll see in the morning. Roblox is having terrible issues right now for the past few hours, so I will wait till tomorrow just to see if it works! I’ll make sure to keep you updated!

Thank you! β€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Ž

Ok β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž β€Žβ€Žβ€Ž

So i just edited it. Will work now

Sorry, in my first post, I was talking about the second script instead of the first. But in the script that @Spellwastaken provided, there’s a few problems:

  1. Using a forever wait() loop is always a bad choice. This is very performance costly and I don’t see why you would use it over a .Changed connection, which would only fire when the Coins value CHANGE.
  2. In Line 10, I think you accidentally delete the period between β€œnew” and β€œCoinsInfo”.

Here just change your local script into this:

local Players = game:GetService("Players")
local plr = script.Parent.Parent.Parent
local leaderstats = plr:WaitForChild("leaderstats")
local cash = leaderstats:WaitForChild("Coins")
local gui = script:WaitForChild("Coins")

local dif = 0
delay(.25, function()
    dif = cash.Value
end)

cash.Changed:Connect(function()
	if dif < cash.Value then
		local random = math.random(1, 900)
		local xnew = random / 1000
		local new = gui:Clone()
		new:WaitForChild("CoinsInfo").Text = "+".. cash.Value - dif
		new.Position = UDim2.new(xnew, 0, 1, 0)
		new.Parent = script.Parent
		dif = cash.Value
		wait(0.1)
		new:TweenPosition(UDim2.new(new.Position.X, 0, -0.1, 0))
		wait(2)
		new.Parent = nil
	else
		dif = cash.Value
	end
end)
1 Like

Thank you, it worked! I really do appreciate it!

If there are more than one correct answers, you should choose the first one because the people that replied after could be copying the first person. It would be unfair for others. Please change your solution mark.

Thank you for setting the solution correctly