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 the player's level to show up as well?

Everything else works fine, the player's name shows up above the player's head, the level display GUI displays the level value on the player's UI, but I cant get the player's level to show up along with the player's username My code for the level is setup like this:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		-- Level

		local level = Instance.new("IntValue")
		level.Name = "Level"
		level.Value = 0
		level.Parent = player
	end)
end)

and the display user and level above head code is setup like this:

game.Players.PlayerAdded:Connect(function(player)
	local level = game.Players.LocalPlayer.Level
	local clone = script.Rank:Clone()
	clone.Parent = game.Workspace:WaitForChild(player.Name).Head
	clone.Frame.Name1.Text = player.Name
	clone.Frame.Rank.Text = level.Value
	
	player.CharacterAdded:Connect(function()
		local level = game.Players.LocalPlayer.Level
		local clone = script.Rank:Clone()
		clone.Parent = game.Workspace:WaitForChild(player.Name).Head
		clone.Frame.Name1.Text = player.Name
		clone.Frame.Rank.Text = level.Value
	end)


end)

Every time I check the output it either says Level isn't a valid member of (my username) or attempt to index nil with Level

2 comments

0

Is this a local script or a regular script?

0

both are regular scripts

1 answer

You can't Have a localplayer inside a regular script you already have a player argument inside the PlayerAdded Function.

if you want to call the level value if it's already created use this

local level = player:WaitForChild("Level")

if you want to call a character and you already have a CharacterAdded function use this instead

local head = char:FindFirstChild("Head")

you can also combine the two scripts just letting you know

game.Players.PlayerAdded:Connect(function(player)
        local level = Instance.new("IntValue")
        level.Name = "Level"
        level.Value = 0
        level.Parent = player

        local clone = script.Rank:Clone()
        clone.Parent = game.Workspace:WaitForChild(player.Name).Head
        clone.Frame.Name1.Text = player.Name
        clone.Frame.Rank.Text = level.Value

        player.CharacterAdded:Connect(function(char) -- Character argument is already here so you don't need to find the character in workspace
                local head = char:FindFirstChild("Head")
                if head then -- Checking if head is not nil
                    local clone = script.Rank:Clone()
                    clone.Parent = head
                    clone.Frame.Name1.Text = player.Name
                    clone.Frame.Rank.Text = level.Value
                end
            end)
    end)

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