Problems with Loading a Character!

Hi guys!

I’m pretty confused where I could’ve gone wrong here, as I can’t see a problem immediately.
The code below triggers from a remote, then records the player position, re-loads the players character, and then teleports the player back to the recorded position.

However, when I run the code, the character is not properly reloaded and instead appears as a basic gray avatar, which I don’t think is something that should happen when a player’s avatar is reloaded (or certainly not what I want!)

I don’t have a problem with the position recording and teleporting to the recorded position, only the character not loading properly, using Player:LoadCharacter().

Not sure if this is my coding or a Roblox problem, but I’m hoping a kind commenter can shed some light for me on the problem!

My Code:

-- Detect when UnAFK Remote is triggered
UnAFK_Rem.OnServerEvent:Connect(function(Player)
	-- Record player's current position
	local character = Player.Character
	local position = character.HumanoidRootPart.Position
	-- Reset player's avatar
	Player:LoadCharacter()
	-- Wait for the character to load
	repeat
		wait()
		character = Player.Character
	until character ~= nil
	-- Reset player's position to the recorded position
	character.HumanoidRootPart.CFrame = CFrame.new(position)
end)

Video showing the problem (Hope it works):

Thanks.

I only modified the code a little bit due to some weird stuff I saw which did not seem right, let me know if this works

UnAFK_Rem.OnServerEvent:Connect(function(Player)
	-- Record player's current position
	local character = Player.Character
	local position = character.HumanoidRootPart.Position
	-- Reset player's avatar
	Player:LoadCharacter()
	-- Wait for the character to load
	repeat
		wait()
	until Player.Character
	-- Reset player's position to the recorded position
	local newChar = Player.Character
	newChar.HumanoidRootPart.CFrame = CFrame.new(position)
end)

prob LoadCharacter() is designed to only load characters to the game and excluding the appearance, HumanoidDescription might help getting the accessories and the cosmetics from the user.

currently i cannot make a script as I’m on phone but I’ll link this

1 Like

I think LoadCharacter can be very helpful for making you wait to respawn, but not to load the appearance of a character. I have this code from one of my games that loads a person’s character appearance on spawn.

local function onPlayerAdded(player)
	local user = player.UserId --defines userid as ID of player who spawned
	wait(0.1)
	local char = player.Character
	char.Humanoid:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(user)) --applies description of avatar gathered from userid onto the humanoid of the dummy
end




local Players = game:GetService("Players")

local function onCharacterAdded(character)
	local function onPlayerAdded(player)
		local user = player.UserId --defines userid as ID of player who spawned
		wait(0.1)
		local char = player
		char.Humanoid:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(user)) --applies description of avatar gathered from userid onto the humanoid of the dummy
	end
end

game.Players.PlayerAdded:Connect(onPlayerAdded)
game.Players.PlayerAdded:Connect(onCharacterAdded)

you can probably modify this code to load the appearance whenever the player comes back from AFK.