So before anything the code works. If I remove the UserId part then it does not. So I do not know why it prompts a error when it actually works
The script is a local script! Error
Players.3DReality.PlayerGui.bk.MenuGuiHandler:585: attempt to index nil with ‘UserId’ - Client - MenuGuiHandler:585
Code
local ImageSize = Enum.ThumbnailSize.Size420x420
local ImageType = Enum.ThumbnailType.HeadShot
local players = game.Players
local PlayerToGrab = players:FindFirstChild(Server:GetAttribute(Plr.Name))
local PlayerImage = game.Players:GetUserThumbnailAsync(PlayerToGrab.UserId, ImageType, ImageSize)
The line that is erroring but not actually erroring
local PlayerImage = game.Players:GetUserThumbnailAsync(PlayerToGrab.UserId, ImageType, ImageSize)
Like I said the code works fine but its prompting a error in the output even though its proving the picture and im just trying to keep the output clean
The Full Function if that might help. Like I stated it works but just roblox says it erroring when it not lol. Like everything works im just trying to stop a false error prompt
function LobbyEvent(Type, Server)
ServerLeaverUI.TextButton.Activated:Connect(function()
MainScreenUI.BackGround.Visible = true
MainMenu.Visible = true
ServerAdjustmentEvent:FireServer(Server)
end)
if Type == "Update" then
LobbySurfaceUI.BackGround.MapBackGround.Image = MapImages:FindFirstChild(Server:GetAttribute("MapName")).Texture
for i, Plr in pairs( LobbySurfaceUI.BackGround:GetChildren()) do
if Server:GetAttribute(Plr.Name) then
local ImageSize = Enum.ThumbnailSize.Size420x420 -- Thumbnail Size
local ImageType = Enum.ThumbnailType.HeadShot -- Thumbnail Type
local players = game.Players
local PlayerToGrab = players:FindFirstChild(Server:GetAttribute(Plr.Name))
print(Server:GetAttribute(Plr.Name))
local PlayerImage = game.Players:GetUserThumbnailAsync(PlayerToGrab.UserId, ImageType, ImageSize) -- Gets Image from UserId
print("Player = ", PlayerToGrab)
print("Type = ", ImageType)
print("Size = ", ImageSize)
Plr.Image = PlayerImage
WarTableBillbord.PlayerCounter.Text = (Server:GetAttribute("CurrentPlayers").."/"..Server:GetAttribute("MaxPlayers"))
Server.AttributeChanged:Connect(function()
LobbyEvent(Type, Server)
end)
end
end
end
end
See thats what I was thinking I spent a couple hours tryna figure out I think it might just be a bug? I am unsure. Like it works its not affecting the code its just prompting errors.
You called “FindFirstChild” with PlayerToGrab, but you never actually added a check to see if it’s an existing value inside of Players Service.
Simply add a “if PlayerToGrab then” right after the variable and see if this stops the error. You might have objects in that frame that aren’t actually a player that exists or you have called this function multiple times before said player exists, explaining why it works but errors at the same time.
That’s only checking the attribute, not the “PlayerToGrab” variable. You called FindFirstChild but never actually checked it. You need to check it on the client so it doesn’t error for a nil value.
You need to check that “PlayerToGrab” was found otherwise it will return as nil, and you cannot index “UserId” with a nil value.