Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I better define leaderstats?

Hello. I am having issues with this script where leaderstats is underlined in blue so the script won't work. Should I have it in a local script? I currently have the script in Workspace. The script abbreviates large amounts of Cash on the leaderboard.

function Convert(num)
local x = tostring(num)
if #x>=13 then
local num1 = (#x-12)
return x:sub(0,(num1)).."."..(x:sub(#x-10,(#x-10))).."Q+" --Quadrillion
elseif #x>=10 then
    local num1 = (#x-9)
    return x:sub(0,(num1)).."."..(x:sub(#x-7,(#x-7))).."B+" --Billion
elseif #x>= 7 then
 local num1 = (#x-6)
 return x:sub(0,(num1)).."."..(x:sub(#x-5,(#x-5))).."M+" --Million
elseif #x>=4 then
    return x:sub(0,(#x-3)).."."..(x:sub(#x-2,(#x-2))).."K+" --Thousand
else
return num
end
end

local number = leaderstats.Money

number.Changed:connect(function()
    number.Value = Convert(number.Value)
end)

1 comment

0

Even if something is underlined in blue, that doesn't mean it won't work. There are many situations when a warning will show that are invalid.

1 answer

✓ Accepted answer

Try this in a script

function playeradd(player)
local leaderstat = Instance.new("StringValue",player)
leaderstat.Name = "leaderstats"
local gold = Instance.new("NumberValue",player) --creates real gold but the display cant be seen
gold.Name = "Gold"
gold.Value = 10 --starter gold
local foolsgold = Instance.new("StringValue",leaderstat) --creates the fake gold that shows on the leaderboard
foolsgold.Name = "Gold"
foolsgold.Value = 10 --starter gold
end

game.Players.PlayerAdded:connect(playeradd) -- calls playeradd when a player joins

and this in a local script (put it inside of starterplayerscripts inside of starterplayer)

function Convert(num)
local x = tostring(num)
if #x>=16 then
local num1 = (#x-15)
return x:sub(0,(num1)).."."..(x:sub(#x-13,(#x-13))).."QN+" --added Quintillion for fun :P
elseif #x>=13 then
local num1 = (#x-12)
return x:sub(0,(num1)).."."..(x:sub(#x-10,(#x-10))).."QD+" --Quadrillion
elseif #x>=10 then
	local num1 = (#x-9)
	return x:sub(0,(num1)).."."..(x:sub(#x-7,(#x-7))).."B+" --Billion
elseif #x>= 7 then
local num1 = (#x-6)
return x:sub(0,(num1)).."."..(x:sub(#x-5,(#x-5))).."M+" --Million
elseif #x>=4 then
	return x:sub(0,(#x-3)).."."..(x:sub(#x-2,(#x-2))).."K+" --Thousand
else
return num
end
end

local number = game.Players.LocalPlayer.leaderstats.Gold

game.Players.LocalPlayer.Gold.Changed:connect(function()
	number.Value = Convert(game.Players.LocalPlayer.Gold.Value) --chages the foolsgold display to whatever Convert() spits out
end)

just change all of the golds to cash or whatever your currency is (this was tested)

This discussion is preserved as it was. New answers, comments, and votes are closed.