Attempt to index nil with Player Image

Hello Developers,

I am making a custom leaderboard for mobile players in my game
Turns out it has an error

But its actually there, even in studio and in game
image

Script:
I am testing it so I’ve made it work with some key on pc

local gui = game.ReplicatedStorage:WaitForChild("LeaderboardGuiFrame")
local uis = game:GetService("UserInputService")

local function getplayers()
    if uis.KeyboardEnabled == true then
        for i = 1,#game.Players:GetPlayers() do
            local clone = gui:Clone()
            local currentplayer = game.Players:GetPlayers()[i]
            clone.PlayerName.Text = currentplayer.Name
            clone.PlayerDisplayName.Text = currentplayer.DisplayName
            clone.Parent = script.Parent
            clone.PlayerImage.Image = game.Players:GetUserThumbnailAsync(currentplayer.UserId,Enum.ThumbnailType.HeadShot,Enum.ThumbnailSize.Size100x100)
            clone.Position = UDim2.new(0,0,0.05,0)
        end
    end
end

uis.InputBegan:Connect(function(key)
    if key.KeyCode == Enum.KeyCode.L then
        getplayers()
    end
end)

Are you adding the PlayerImage object at a later time in the Gui? You could just print every children of the clone and check what everything outputs back

for _, Object in pairs(clone:GetChildren()) do
    print(Object)
end

Player image is there, but in local script it says it does not exist

It still wouldn’t hurt to print regardless, maybe you’re referencing the wrong object or something?

1 Like

Try adding a :WaitForChild(). This happened because the GUI did not load.

1 Like

I did that and added a thing called wait(5) before changing, same error

Could you provide some more information regarding your problem as of where some certain instances are located in the explorer at and line of code? Or sharing the file if you don’t mind.

1 Like

Please share the updated script.

1 Like

Name the PlayerImage something else because it might be a sensitive name. If it didn’t work, did you create the PlayerImage using a script?

2 Likes
local gui = game.ReplicatedStorage:WaitForChild("LeaderboardGuiFrame")
local uis = game:GetService("UserInputService")

local function getplayers()
    if uis.KeyboardEnabled == true then
        for i = 1,#game.Players:GetPlayers() do
            local clone = gui:Clone()
            wait(5)
            local currentplayer = game.Players:GetPlayers()[i]
            clone.PlayerName.Text = currentplayer.Name
            clone.PlayerDisplayName.Text = currentplayer.DisplayName
            clone.Parent = script.Parent
            clone:WaitForChild("PlayerImage").Image = game.Players:GetUserThumbnailAsync(currentplayer.UserId,Enum.ThumbnailType.HeadShot,Enum.ThumbnailSize.Size100x100)
            clone.Position = UDim2.new(0,0,0.05,0)
        end
    end
end

uis.InputBegan:Connect(function(key)
    if key.KeyCode == Enum.KeyCode.L then
        getplayers()
    end
end)

No its not created by a script or local script

Sir, its a local script and its a mobile leaderboard but turns out there is an error

Name it something else then bro.

I did, still same error tell how to fix please

I think I know now. When you join the game, instead of going to starter player gui, go to this path:
Players>Woodx>PlayerGui>…
and then find the path to your leaderboardGuiFrame and check if it is there. I suspect that it might not be there, so that means you called Destroy() on the object. Check for script where you destroyed the player image