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

Body Color script is not working? "Player is not a valid member of workspace"

Asked by 6 years ago

I need to change the players body color once they spawn. I've tried many things like..

game.Workspace.newluigibro.Head.BrickColor = BrickColor.new("Bright Yellow")

or

game.Workspace.Player.Head.BrickColor = BrickColor.new("Bright Yellow")

I kept on getting errors like "newluigibro is not a valid member of Workspace" "Player is not a valid member of Workspace"

Any help?

0
Try Player.Character fr2013 88 — 6y
0
LOL User#21908 42 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago

You need to wait() for yourself OoOoOooo SPooKY anyways, try this..

game.Players.PlayerAdded:Connect(function(p)
    wait(.5)
    local char = p.Character
    for _, v in pairs(char:GetChildren()) do
        if v.ClassName == "Part" then
            v.BrickColor = BrickColor.new("Bright Yellow")
        end
    end
end)

Also, If you cannot see the face, just remove the accessories from the player ;o

What I did: When the player is added, it waits .5 just in case the character wasn't added, then it runs a loop in the character hoping to find the legs, the head, arms, etc cause you said "body color" and not "head color" and then I change it to bright yellow.. YEEET

1
Why do you need `wait(.5)`? Why not use `CharacterAdded`? TheeDeathCaster 2368 — 6y
Ad
Log in to vote
1
Answered by 6 years ago

The issue you have is more likely to be that the script ran before the character was even there. You don't need to do game.Workspace.newluigibro since there is a property of the Player's instance which is player.Character which returns the actual player. To accomplish what you are trying to do you can use the event player.CharacterAdded which is fired every time the player's character is spawned in.

game.Players.PlayerAdded:Connect(function(player) -- fires every time a new player joins.
    player.CharacterAdded:Connect(function(character) -- event of player which returns the character

        local head = character:WaitForChild("Head") -- Waits for the head to be added
        head.BrickColor = BrickColor.new("Bright Yellow") -- Sets the head to the new BrickColor, Bright Yellow!
    end)
end)
1
^ TheeDeathCaster 2368 — 6y

Answer this question