Script of gui won't ge,erate player character

when i type player name and i press enter in textbox the searched player’s character doesn’t get generated.
script:

local box = script.Parent
local img = box.Parent:WaitForChild("PlayerImage")
local players = game:GetService("Players")

box.FocusLost:Connect(function(enterpressed, loser)
	if enterpressed then
		local isUserId = tonumber(box.Text)
		if not isUserId then
			local userid = game:GetService("Players"):GetUserIdFromNameAsync(box.Text)
			if userid then
				img.Image = players:GetUserThumbnailAsync(userid, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
			end
		else
			img.Image = players:GetUserThumbnailAsync(isUserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
		 local player = players:GetPlayerByUserId(isUserId)
		 local char = player.Character
		 local clone = char:Clone()
		 clone.Parent = workspace
		end
	end
end)

I’ve added some debugging statements and a protected call.

Check Output for Warnings: Run the script and check the output window for any warnings that indicate what might be going wrong.

local box = script.Parent
local img = box.Parent:WaitForChild("PlayerImage")
local players = game:GetService("Players")

box.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		local isUserId = tonumber(box.Text)
		local userid
		
		-- Check if the input is a username or a user ID
		if not isUserId then
			-- Input is a username, so get the user ID from the username
			local success, result = pcall(function()
				return players:GetUserIdFromNameAsync(box.Text)
			end)
			
			if success then
				userid = result
			else
				warn("Failed to get user ID from username:", result)
				return
			end
		else
			-- Input is a user ID
			userid = isUserId
		end
		
		-- Get the player's thumbnail image
		local success, thumbnail = pcall(function()
			return players:GetUserThumbnailAsync(userid, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
		end)
		
		if success then
			img.Image = thumbnail
		else
			warn("Failed to get user thumbnail:", thumbnail)
		end
		
		-- Get the player object by user ID
		local player = players:GetPlayerByUserId(userid)
		if player then
			-- Get the player's character
			local char = player.Character
			if char then
				-- Clone the character and parent it to the workspace
				local clone = char:Clone()
				clone.Parent = workspace
			else
				warn("Player character not found")
			end
		else
			warn("Player not found with user ID:", userid)
		end
	end
end)
1 Like

You need to enable Archivable for the character

shows image but doesn’t load their character

@WeirdOddz is correct. You need to mark the character as archivable before cloning.

local box = script.Parent
local img = box.Parent:WaitForChild("PlayerImage")
local players = game:GetService("Players")

box.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		local isUserId = tonumber(box.Text)
		local userid
		
		-- Check if the input is a username or a user ID
		if not isUserId then
			-- Input is a username, so get the user ID from the username
			local success, result = pcall(function()
				return players:GetUserIdFromNameAsync(box.Text)
			end)
			
			if success then
				userid = result
			else
				warn("Failed to get user ID from username:", result)
				return
			end
		else
			-- Input is a user ID
			userid = isUserId
		end
		
		-- Get the player's thumbnail image
		local success, thumbnail = pcall(function()
			return players:GetUserThumbnailAsync(userid, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
		end)
		
		if success then
			img.Image = thumbnail
		else
			warn("Failed to get user thumbnail:", thumbnail)
		end
		
		-- Get the player object by user ID
		local player = players:GetPlayerByUserId(userid)
		if player then
			-- Get the player's character
			local char = player.Character
			if char then
				-- Clone the character and parent it to the workspace
                                char.Archivable = true
				local clone = char:Clone()
				clone.Parent = workspace
			else
				warn("Player character not found")
			end
		else
			warn("Player not found with user ID:", userid)
		end
	end
end)```
1 Like

doesn’t work tho
11111111111111

Pretty sure there’s a thing called Player:LoadCharacter()

Also there’s Player:LoadCharacterWithHumanoidDescription()

GetPlayerByUserId only works if the player is in the game. Who’s name are you trying? If they aren’t in the game, you’ll have to clone a dummy and apply their appearance to the dummy.

Yes, make sure the player is in the game, like @Pure_Bacn said, if they aren’t you’ll need to use a dummy/another rig and edit Humanoid.HumanoidDescription (A Instance parented to the Humanoid)