This script needs help fixing!

it still says 0 instead of 1t
image
see

please help again it still wont work

could you give me your exact gem value

It’s not updating because in the gems.Changed event you are setting the gemsLabel.Text to the textGems variable that is only set once when the script first runs. Changing gemsLabel.Text = textGems to gemsLabel.Text = text should work.

ok when i play the leaderstats say 1t

I think this topic wouldn’t have been this long if we simply take a look at how UI is loaded: They load with the character, moments after the player joins, not at the exact same time. That means any code under ScreenGuis will not receive the initial value set by the server (if that’s what’s done) because Gems may have been set earlier before the UI is loaded (or in other words, the first time the value is changed, your UI code did not receive that because it was not loaded yet).

Move the anonymous callback to its own, connect the function to the value’s .Changed, and run the function at least once.

This is nearly the same code that this topic started with, with some fixes:

local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")

local formatNumber = require(replicatedStorage:WaitForChild("FormatNumberAlt"))
local player = players.LocalPlayer

local gems = player:WaitForChild("leaderstats"):WaitForChild("Gems")

-- WaitForChild should not be used when we know the target objects will exist before the script loads. WaitForChild is only used when dealing with network replication stuff.
local gemsLabel = script.Parent.Gems.Label

local textGems = formatNumber.FormatCompact(tonumber(gems.Value))
gemsLabel.Text = textGems

local function update() -- Callback function separated to its own block.
	textGems = formatNumber.FormatCompact(gems.Value)
	gemsLabel.Text = textGems
end

gems.Changed:Connect(update)

update() -- Run once to check if the value was changed by the server before the UI is loaded.

Let us know if something wrong happens, and send us console errors related to your issue if there are any.

EDIT: Removed .Simple in line 4. OP uses the alternative API of FormatNumber, not the main API.

thanks but doesnt work for some reason, it still says 0 instead of my leaderstats currency number

Have you checked for any errors in the Output window? Have you set up suffixes in the FormatNumber module (10M, 23k, 2qd)?

wait how do i set up the suffixes like where aboutse in the script

try this:

local players = game:GetService("Players")

local player = players.LocalPlayer

local gems = player:WaitForChild("leaderstats"):WaitForChild("Gems")

local gemsLabel = script.Parent:WaitForChild("Gems"):WaitForChild("Label")

while true do
	wait()
	gemsLabel.Text = gems.Value
end

doesn’t work, thanks though. :grinning:

if this is not work then something in the variables dont exist

oh yep it works now but insdead of not shortening it to 1t or something it says this:
image

so try this:

local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")

local formatNumber = require(replicatedStorage:WaitForChild("FormatNumberAlt"))
local player = players.LocalPlayer

local gems = player:WaitForChild("leaderstats"):WaitForChild("Gems")

local gemsLabel = script.Parent:WaitForChild("Gems"):WaitForChild("Label")

local textGems = formatNumber.FormatCompact(tonumber(gems.Value))
gemsLabel.Text = textGems

while true do
	wait()
	local text = formatNumber.FormatCompact(tonumber(gems.Value))
	gemsLabel.Text = textGems
end

if this is not work so the “FormatNumberAlt” module in replicated storage is not working

yea it aint working now, i wonder whats wrong with formatbumberalt

so what should i do now about the script?

im making new script maybe its take some time

I completely missed the fact that you were using the older, alternative API of the FormatNumber module. Using the same code I provided earlier, remove .Simple in this line:

local formatNumber = require(replicatedStorage:WaitForChild("FormatNumberAlt").Simple)

The linked post is updated.

I reckon you use MoneyLib. It’s good and reliable

um the line is kinda crossed out…