Now, I am making a game. I have 2 of THE SAME EXACT SCRIPTS and the xp in the output is this: Xp is not a valid member of Folder.
Here is the script:
function comma_value(amount)
local formatted = amount
while true do
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
if (k==0) then
break
end
end
return formatted
end
local shorten = function(number)
if(number > -1 and number < 1000)then
return tostring(math.floor(number/10^-1)/10) .. "";
elseif(number > 1000 and number < 1000000)then
return comma_value(number)
elseif(number > 1000000 and number < 1000000000)then
return tostring(math.floor(number/10^5)/10) .. "m";
elseif(number > 10^9 and number < 10^12)then
return tostring(math.floor(number/10^8)/10) .. "b";
elseif(number > 10^12 and number < 10^15)then
return tostring(math.floor(number/10^11)/10) .. "t";
elseif(number > 10^15 and number < 10^18)then
return tostring(math.floor(number/10^14)/10) .. "Qd";
end
end
local plr = game.Players.LocalPlayer
local Stats = plr.leaderstats
local function UpdateTextLabel()
script.Parent.Text = "Xp " .. shorten(Stats.Xp.Value)
end
Stats.Xp.Changed:Connect(function()
UpdateTextLabel()
end)
Here is my Level script:
function comma_value(amount)
local formatted = amount
while true do
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
if (k==0) then
break
end
end
return formatted
end
local shorten = function(number)
if(number > -1 and number < 1000)then
return tostring(math.floor(number/10^-1)/10) .. "";
elseif(number > 1000 and number < 1000000)then
return comma_value(number)
elseif(number > 1000000 and number < 1000000000)then
return tostring(math.floor(number/10^5)/10) .. "m";
elseif(number > 10^9 and number < 10^12)then
return tostring(math.floor(number/10^8)/10) .. "b";
elseif(number > 10^12 and number < 10^15)then
return tostring(math.floor(number/10^11)/10) .. "t";
elseif(number > 10^15 and number < 10^18)then
return tostring(math.floor(number/10^14)/10) .. "Qd";
end
end
local plr = game.Players.LocalPlayer
local Stats = plr.leaderstats
local function UpdateTextLabel()
script.Parent.Text = "Level " .. shorten(Stats.Level.Value)
end
Stats.Level.Changed:Connect(function()
UpdateTextLabel()
end)
All I am asking, what should I do to fix this...

3 comments
give us what part of the script is going wrong and make sure to give us the hierarchy of leaderstats and xp too
what he said
Xp script line 36