Using GetUserThumbnailAsync stops script

I am currently creating a system where two players who are fighting in a match have their thumbnail headshots displayed. Everything else works fine, but the script simply stops running when it gets to GetUserThumbnailAsync. I have confirmed with print statements that it does indeed stop there. I have gotten no errors or warnings, and I haven’t found another instance of this happening. I also enabled API Access and HTTP Requests in game settings.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local roundBeginClientEvent = ReplicatedStorage.Events:WaitForChild("RoundBeginClient")
local player1Icon = script.Parent:WaitForChild("Player1Icon")
local player2Icon = script.Parent:WaitForChild("Player2Icon")

roundBeginClientEvent.OnClientEvent:Connect(function(player1, player2)
	local player1Thumbnail, player1Ready = Players:GetUserThumbnailAsync(player1.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
	local player2Thumbnail, player2Ready = Players:GetUserThumbnailAsync(player2.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
	
	player1Icon.Image = (player1Thumbnail and player1Ready) or "rbxassetid://0"
	player2Icon.Image = (player2Thumbnail and player2Ready) or "rbxassetid://0"
end)
1 Like

Hya, the issue you are running is that you are writing the code wrong. This is how the Player1Icon.Image and Player2Icon.Image should be:

player1Icon.Image = player1Thumbnail or “rbxassetid://0”
player2Icon.Image = player2Thumbnail or “rbxassetid://0”

— — :slight_smile:

1 Like

Well I guess the docs lied to me! I will fix that, but the problem is that it doesn’t get to that point in the script in the first place. Like I said, it stops running as soon as it attempts to run the first GetUserThumbnailAsync statement.

As I can’t see the full code, here are some possible errors coming:

  1. player1Ready and player2Ready are completely useless as they don’t do nothing

  2. How the event is being fired to the clients

The docs were correct.
This is likely caused by another script rather than the Get Async.
Can you try commenting all the code in the connection and see if it still stops?

It’s a remote event connection, I doubt there is another thing that can stop it. As he said, he even confirmed that the code stops right before using the UserThumbnail.

Well, turns out commenting out the event-related code in the script fixed it, somehow…
Here’s the new script that DOES work. And yes, the event does fire.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local roundBeginClientEvent = ReplicatedStorage.Events:WaitForChild("RoundBeginClient")
local player1Icon = script.Parent:WaitForChild("Player1Icon")
local player2Icon = script.Parent:WaitForChild("Player2Icon")

wait(5)

local player1Thumbnail, player1Ready = Players:GetUserThumbnailAsync(3755358054, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
	
if player1Ready then
	player1Icon.Image = player1Thumbnail
else
	player1Icon.Image = "rbxassetid://0"
end

(comments removed to look more coherent)

Have u tried to print the Player1.UserId and Player2.UserId to see if there is something sent wrong?

I have, both are player objects and I was able to print the usual player info. (Name, UserId, etc.) I guess I’ll send the function that fires the remote event to the client and the main script that uses that function.

Function: (in a modulescript)

function Round.begin(player1, player2)
	roundBeginClientEvent:FireAllClients(player1, player2) --here to update GUI for each person
	player1:LoadCharacter()
	player2:LoadCharacter()
	
	player1.Character:WaitForChild("HumanoidRootPart").CFrame = player1Spawn.CFrame
	player2.Character:WaitForChild("HumanoidRootPart").CFrame = player2Spawn.CFrame
	--add the cutscene into this function or make another seperate cutscene function? not sure yet
end

and here’s the part of the main script that uses it:

roundBeginEvent.OnServerEvent:Connect(function(player1, player2)
	Round.begin(player1, player2)
end)

It’s important to note I have a gui that fires the SERVER round begin event and allows you to input names, as a temporary measure until I finish the round system.

Ah, I see ur starting the round when someone fires the event, in that case, you would need some sanity checks as an exploiter could simply spam fire the event.

  1. If you want to update the images for every client, you should change them dirrectly from server as new players won’t see the changes ( you would need to add a function that detects whose players are in the round )

In conclusion, I suggest making the code server sided if u want to achieve something that updates for the server ( every client ).

Alright, I will try that. I’ll reply with how well it worked later, and any specifics for those who find this thread later. I’ll just mark your reply as solution for now.

EDIT:
It works! There’s multiple scripts involved due to me trying to make a modular, module based system so I won’t be posting it. Sorry ¯_(ツ)_/¯

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.