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

Why wont my script work?

I am trying to make a script that runs on While True Do, And doesnt Fail but the Failing part is bad...

Here is the script.

game.Players.PlayerAdded:connect(function(plr)
print("I Didnt Break")
while true do
	print("I Didnt Break")
plr.Character.Head.Mesh.MeshId = "http://www.roblox.com/asset/?id=19999257"
print("I Didnt Break")
plr.Character.Head.Mesh.TextureId = "http://www.roblox.com/asset/?id=20001023"
print("I Didnt Break")
plr.Character.Head.Transparency = "0.25"
print("I Didnt Break")
end
end)

The Plr.Character, Via Character is said to be a nil value...

1 answer

✓ Accepted answer

The correct way of using a player's character is through the CharacterAdded event in the player. In your specific case, you'll also want to make sure the head also exists in the player before messing with it. To do that, you'll need the :WaitForChild() function to safely get the head and use it.

game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(char)
		local head = char:WaitForChild('Head')
		-- do stuff with the head
	end)
end)

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