Player is not a valid member of the workspace upon respawning

When I respawn a player, I set their camera to their new character’s humanoid. This works if the character is already predefined, however, it fails when I try to use Player.Character since the player is no longer part of the workspace.

I’ve tried to go about it using WaitForChild(“Player”), however, that gives me an infinite yield error and breaks the whole script. Does anyone know how I can go about fixing this?

1 Like


local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

This should be the solution to your issue. If it persists, do let me know. It always works for me. The character variable always check and make sure that the player’s character is there in the workspace even if they reset/respawned. If it works, you can just attach another variable called humanoid to make sure the humanoid of the player’s character exists. You can do this;

local humanoid = character:FindFirstChildWhichIsA("Humanoid")

Works perfectly now! This is the final edit I made, it seems like all that was necessary was to add this part circled in red. I tried game:GetService(“Players”) before, but I didn’t add .LocalPlayer after it which is probably what caused the infinite yield error.

Thanks for the help!

1 Like

No problem, glad to help. Do note that you should probably reference the character and humanoid in the future if you have a custom rig or the player didn’t load in properly which you would use;

local character = player.Character or player.CharacterAdded:Wait()

Otherwise it would likely return a not a valid member error. But either way, congrats and cheers mate.

1 Like