Values not showing up in the UI

So i’ve got a UI for Rebirths and Shinies and they both seem to not be showing the value in the leaderstats

i’m getting this error message

they stem from this script, line 47
any fixes?

-- Configuration
-- The suffixes for abbreviation in every power of thousands.
local COMPACT_SUFFIX = {
	"K", "M", "B", "T"
}
local CACHED_SKELETON_SETTINGS = true
--

local MainAPI = require(script.Parent.Main)
local FormatNumberSimpleAPI = { }

local SKELETON_CACHE = if CACHED_SKELETON_SETTINGS then { } else nil
local COMPACT_SKELETON_CACHE = if CACHED_SKELETON_SETTINGS then { } else nil

function FormatNumberSimpleAPI.Format(value: number, skeleton: string?): string
	local success
	local formatter = nil

	assert(type(value) == "number", "Value provided must be a number")

	if skeleton == nil then
		skeleton = ""
	end
	assert(type(skeleton) == "string", "Skeleton provided must be a string")

	if CACHED_SKELETON_SETTINGS then
		formatter = SKELETON_CACHE[skeleton]
	end

	if not formatter then
		success, formatter =
			MainAPI.NumberFormatter.forSkeleton(skeleton)
		assert(success, formatter :: string)

		if CACHED_SKELETON_SETTINGS then
			SKELETON_CACHE[skeleton] = formatter
		end
	end

	return (formatter :: MainAPI.NumberFormatter):Format(value)
end

function FormatNumberSimpleAPI.FormatCompact(value: number, skeleton: string?): string
	local success
	local formatter = nil

	assert(type(value) == "number", "Value provided must be a number")

	if skeleton == nil then
		skeleton = ""
	end
	assert(type(skeleton) == "string", "Skeleton provided must be a string")

	if CACHED_SKELETON_SETTINGS then
		formatter = COMPACT_SKELETON_CACHE[skeleton]
	end

	if not formatter then
		success, formatter =
			MainAPI.NumberFormatter.forSkeleton(skeleton)
		assert(success, formatter :: string)

		formatter = (formatter :: MainAPI.NumberFormatter)
			:Notation(MainAPI.Notation.compactWithSuffixThousands(COMPACT_SUFFIX))

		if CACHED_SKELETON_SETTINGS then
			COMPACT_SKELETON_CACHE[skeleton] = formatter
		end
	end

	assert(#COMPACT_SUFFIX ~= 0, "Please provide the suffix abbreviations for FormatCompact at the top of the Simple ModuleScript")

	return formatter:Format(value)
end

return table.freeze(FormatNumberSimpleAPI)

Could you provide the script / code from the script where you’re actually calling the function?

theres 2 of them

Rebirths:

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

local FormatNumber = require(ReplicatedStorage.Libs.FormatNumber.Simple)
local Remotes = ReplicatedStorage.Remotes

local Player = Players.LocalPlayer
local PlayerGui = Player.PlayerGui

local Gui = PlayerGui:WaitForChild("Left")
local Frame = Gui.Frame.Rebirths

local Rebirths = Frame.Amount

local REBIRTH_TEXT_TEMPLATE = "Rebirth: AMOUNT"

local function UpdateRebirths(amount: number)
	Rebirths.Text = REBIRTH_TEXT_TEMPLATE:gsub("AMOUNT", FormatNumber.FormatCompact(amount))
end

UpdateRebirths(Remotes.GetData:InvokeServer("Rebirths"))
Remotes.UpdateRebirths.OnClientEvent:Connect(UpdateRebirths)

Shinies:

local function UpdateCurrency(currency: "mony" | "shinies", amount: number)
	if currency == "mony" then
		UpdateClicksPerSecond(amount)
		mony.Text = FormatNumber.FormatCompact(amount)
	elseif currency == "shinies" then
		shinies.Text = FormatNumber.FormatCompact(amount)
	end
end

UpdateCurrency("mony", Remotes.GetData:InvokeServer("mony"))
UpdateCurrency("shinies", Remotes.GetData:InvokeServer("shinies"))

Remotes.UpdateMony.OnClientEvent:Connect(function(amount)
	UpdateCurrency("mony", amount)
end)
Remotes.UpdateShinies.OnClientEvent:Connect(function(amount)
	UpdateCurrency("shinies", amount)
end)

The GetData RemoteFunction may be returning nil or something else that isn’t a number, maybe that check and provide it if you can’t figure out what’s wrong?

I checked and It seems like it should work, but the simplifier module seems to be showing errors

Can you provide the code where you’re returning the value?

idk if its js because its late but i have no idea which value you mean

The value you’re returning to this RemoteFunction.

1 Like

oh right yeah

local function UpdateRebirths(amount: number)
	Rebirths.Text = REBIRTH_TEXT_TEMPLATE:gsub("AMOUNT", FormatNumber.FormatCompact(amount))
end

pretty sure its this

Okay like this is what I mean:

ExampleRemote.OnServerInvoke:Connect(function(value)
-- your code
return (whatever)
end)

This is the script that contains a serverinvoke

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Remotes = ReplicatedStorage.Remotes

local Manager = {}

Manager.Profiles = {}

function Manager.AdjustRebirths(player: Player, amount: number)
	local profile = nil

	if Manager.Profiles[player.UserId] then
		profile = Manager.Profiles[player.UserId]
	else
		profile = {Data = {Rebirths = 0}}
		Manager.Profiles[player.UserId] = profile
	end

	profile.Data.Rebirths += amount

	player.leaderstats.Rebirths.Value = profile.Data.Rebirths
	Remotes.UpdateRebirths:FireClient(player, profile.Data.Rebirths)
end

function Manager.AdjustShinies(player: Player, amount: number)
	local profile = nil

	if Manager.Profiles[player.UserId] then
		profile = Manager.Profiles[player.UserId]
	else
		profile = {Data = {shinies = 0}}
		Manager.Profiles[player.UserId] = profile
	end

	profile.Data.shinies += amount

	player.leaderstats.shinies.Value = profile.Data.shinies
	Remotes.UpdateShinies:FireClient(player, profile.Data.shinies)
end

function Manager.AdjustMony(player: Player, amount: number)
	local profile = nil

	if Manager.Profiles[player.UserId] then
		profile = Manager.Profiles[player.UserId]
	else
		profile = {Data = {mony = 0}}
		Manager.Profiles[player.UserId] = profile
	end

	profile.Data.mony += amount

	player.leaderstats.mony.Value = profile.Data.mony
	Remotes.UpdateMony:FireClient(player, profile.Data.mony)
end

local function GetData(player: Player, directory: string)
	local profile = nil
	if Manager.Profiles[player.UserId] then
		profile = Manager.Profiles[player.UserId]
	else
		profile = {Data = {mony = 0}}
		Manager.Profiles[player.UserId] = profile
	end
	return profile.Data[directory]
end

Remotes.GetData.OnServerInvoke = GetData

return Manager

Okay I’m super late cuz I had a couple of classes but I think I know what’s wrong now.

You’re returning whatever the directory is which you provided the parameter “Rebirths” which doesn’t exist on the Data table as seen here:

So when you’re returning it here:

It’s returning nil because it’s basically doing: return profile.Data[“Rebirths”] which doesn’t exist.

1 Like