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

How do I get a value from a folder? [SOLVED]

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

0

give us what part of the script is going wrong and make sure to give us the hierarchy of leaderstats and xp too

0

what he said

0

Xp script line 36

1 answer

Ok so I solved this my myself, this is all I had to type between lines 32-36 wait(1) script.Parent.Text = "Xp " .. shorten(Stats.Xp.Value) wait(1)

Here was my script:

local MyAnwser = "No. ITS LISTED ABOVE"

Mainly because the xp and level loaded at the same time, the script thought it was not there yet

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