Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I get the player's level to show up as well?

Asked by 3 years ago

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

0
Is this a local script or a regular script? gamingwithjbthepro 76 — 3y
0
both are regular scripts IcyMustard 4 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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

Answer this question