I want to use LoadCharacter on a player’s character when they die. Instead, I get this error:
Here is my code:
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
hum:GetPropertyChangedSignal("Health"):Connect(function()
if hum.Health == 0 then
wait(2)
plr:LoadCharacter()
print("Loading character...")
end
end)
end)
end)
the error shouldn’t affect the outcome of the script, however, to get rid of it just a second argument to WaitForChild with any int, it will make a timeout. If you don’t want a timeout then ignore the error.
Yep, to explain the error it’s very similar to this other post which faces the same infinite yield problem when using player:LoadCharacter().
TL;DR: character is destroyed but the wait for child is still searching for a humanoid within this destroyed character model.
Additionally, @PrismaticShadows should disable character auto load like the example script provided in the documentation to avoid character loading conflict with the default spawn system.
game.Players.CharacterAutoLoads = false
https://developer.roblox.com/en-us/api-reference/function/Player/LoadCharacter