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

Script not killing on PlayerAdded?

Script:

game.Players.PlayerAdded:connect(function(player)
	player.Character.Head:remove()
end)

I just want the player to die when they first join and I am getting this error: Workspace.PlayerAdded:3: attempt to index field 'Character' (a nil value)

Please help! Thanks.

2 answers

✓ Accepted answer

Your script running before player character even spawns. You must add repeat loop into first function, and then wait until character head loads. Or you can wait for Humanoid and set health to 0 (alternate killing way)

game.Players.PlayerAdded:connect(function(player)
	repeat wait() until player.Character
	char = player.Character
	char:WaitForChild("Head"):Destroy() --Wait until head creates, and then destroy it.
end)
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid.Health = 0
	end
end)

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