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

How to make an XP bar?

Why does this XP bar not working?

script.Parent.Parent.Parent.Parent.Parent.leaderstats.XOP.Value I tried didn't work so i had to find a other why to get the stats.

local user = game.Players:GetPlayers()
local stats = user:findFirstChild("leaderstats")
xp = stats:findFirstChild("XOP")
lvl = stats:findFirstChild("Level")

while true do
wait()
local FR = ( xp.Value / (lvl.Value * 100))
script.Parent.Size = UDim2.new( FR , 0 , 0, 10)
end

Error: Script 'Players.Player.PlayerGui.XPGui.Frame.Fill.Script', Line 2 and Players.Player.PlayerGui.XPGui.Frame.Fill.Script:2: attempt to call method 'findFirstChild' (a nil value)

2 comments

0

user is a table, which means it doesn't have a FindFirstChild.

0

Is their another way to find leaderstats?

1 answer

✓ Accepted answer

I tidied your code up a bit. If it didn't work, make sure all your values exist.

local user = game.Players.LocalPlayer -- :GetPlayers() gets all the players and returns a table. Shouldn't really be used at all in localscripts. You only need the local player.
local stats = user:findFirstChild("leaderstats")
xp = stats:findFirstChild("XOP")
lvl = stats:findFirstChild("Level")

local function changed() -- Use events rather than a loop for this type of thing.
	local FR = (xp.Value / (lvl.Value * 100))
	script.Parent.Size = UDim2.new(FR, 0, 0, 10)
end

xp.Changed:connect(changed)
lvl.Changed:connect(changed)

1 comment

0

You did answer on my other question correct you need change findFirstChild to WaitForChild may edit it in here and i will give accept answer. ;)

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