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)
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)