Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why wont my script work? [closed]

Asked by
IcyEvil 260 Moderation Voter
10 years ago

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...

Locked by adark and evaera

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
1
Answered by 10 years ago

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)
Ad