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

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

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?

2 comments

0

Try Player.Character

0

LOL

2 answers

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 comment

1

Why do you need wait(.5)? Why not use CharacterAdded?

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 comment

1

^

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