I had a script that should get a users thumbnail when they join the game, however I’m having some issues.
local ArenaToLobby = RS:FindFirstChild("ArenaToLobby")
local LobbyToArena = RS:FindFirstChild("LobbyToArena")
local backup_thumbnail = "image_string_url"
local playerThumbnails = {}
game.Players.PlayerAdded:Connect(function(player)
-- Store thumbnail from player that joined
local content, isReady = pcall(function()
return Players:GetUserThumbnailAsync(player.UserId,Enum.ThumbnailType.HeadShot,Enum.ThumbnailSize.Size150x150)
end)
playerThumbnails[tostring(player.UserId)] = (isReady and content) or backup_thumbnail
end)
Players.PlayerRemoving:Connect(function(player)
-- Remove stored thumbnail from player that left
if playerThumbnails[tostring(player.UserId)] then
playerThumbnails[tostring(player.UserId)] = nil
end
end)
-- These are bindable events
ArenaToLobby.Event:Connect(function()
LobbyToArena:Fire(playerThumbnails)
end)
In a different script:
playEvent.OnServerEvent:Connect(function()
local playerThumbnails = nil
ArenaToLobby:Fire()
LobbyToArena.Event:Connect(function(thumbnails)
playerThumbnails = thumbnails
end)
if #gamePlayers == 6 then
for i = 3, 1, -1 do
team1[i].RespawnLocation = workspace:FindFirstChild("Sword Fighting Arenas").Arena1.T1Spawn
team2[i].RespawnLocation = workspace:FindFirstChild("Sword Fighting Arenas").Arena1.T2Spawn
end
-- I get an error on these lines saying thats attempting to index the userId with nil.
local content1 = playerThumbnails[tostring(gamePlayers[1].UserId)]
local content2 = playerThumbnails[tostring(gamePlayers[2].UserId)]
local content3 = playerThumbnails[tostring(gamePlayers[3].UserId)]
local content4 = playerThumbnails[tostring(gamePlayers[4].UserId)]
local content5 = playerThumbnails[tostring(gamePlayers[5].UserId)]
local content6 = playerThumbnails[tostring(gamePlayers[6].UserId)]