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

Help with making all players 'Green'?

So what I am trying to do is when a player joins, their character is 'Sea green'. It is not working.

game.Players.PlayerAdded:connect(function(Player)
	Player.CharacterAdded:connect(function(Char)
		for i,v in pairs(Char:GetChildren()) do
			if v['Body Colors'] ~= nil then --'Body Colors' is something in each character if you did not know :P
				if v.ClassName == 'Part' then
					v.BrickColor = BrickColor.new('Sea green')
				end
			end
		end
	end)
end)

1 answer

✓ Accepted answer

On line 4, you're checking if BodyColors is in the part, not the character.

Easy fix. I would actually just get rid of checking for BodyColors all together, but it's up to you.

game.Players.PlayerAdded:connect(function(Player)
	Player.CharacterAdded:connect(function(Char)
		if Char:FindFirstChild('Body Colors') then
			for i,v in pairs(Char:GetChildren()) do
				if v.ClassName == 'Part' then
					v.BrickColor = BrickColor.new('Sea green')
				end
			end
		end
	end)
end)
If you did want to check for body colors, you would use FindFirstChild, which I did on line 3.

You have to destroy BodyColors before changing colors.

If you don't the character will just change back when BodyColors loads. Use WaitForChild to wait for BodyColors, and destroy it.

game.Players.PlayerAdded:connect(function(Player)
	Player.CharacterAdded:connect(function(Char)
		Char:WaitForChild('Body Colors'):Destroy()
		for i,v in pairs(Char:GetChildren()) do
			if v:IsA("Part") then
				v.BrickColor = BrickColor.new('Sea green')
			end
		end
	end)
end)
I also changed the .ClassName to use the IsA function because it seems simpler and will do ultimately the same thing.

Good Luck!

If I helped, please don't forget to accept my answer.

4 comments

0

Error: Body Colors is not a valid member of Model

0

Made me green for 1 second, then turned back normal,

0

read the whole article?

0

We were talking in the chat. I made a few errors in my script so his comments are called for. It's working now though

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