Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

CharacterAdded code messes up when interacting with Character?

game.Players.PlayerAdded:Connect(function(Player)
	local Char = Player.Character or Player.CharacterAdded:Wait()
	wait(3)
	Char:WaitForChild("Humanoid").Health = 0
end)


game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		Character:WaitForChild("Humanoid").Health = 0
	end)
end)

This is basically the same code

I need the player to die so that they respawn as my custom character script

and yes I have tried manually setting the custom character when they join the game

and it still does the same thing

I have tried to do LoadCharacter everything

The code does run but it does not kill the player

I have also tried

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		Character:SetPrimaryPartCFrame(CFrame.new(0,99999,0))
	end)
end)

To see if my code was working but from what I see

Anything relating to the character does not work with characterAdded

when they first join in the game

you need to place a wait

does anyone know a solution to this that does not require something along the lines of doing

wait(5)

Cause this is completely unreliable

1 comment

0

Killing the player when they spawn seems like a bandaid fix. Try setting Players.CharacterAutoLoads to false and Player:LoadCharacter().

1 answer

I’d recommend using

repeat task.wait() until plr.Character

It would check if Character is a children of player. (you would need to put this inside CharacterAdded)

This discussion is preserved as it was. New answers, comments, and votes are closed.