Hello, I am getting an error with my code when I use GetChildren(), but I don't know why that happens. I don't work with this type of function normally, and so I don't know how to fix it. Here's the entire code :
local Color = script.Parent.TeamColor -- TeamColor is a BrickColor value local P = script.Parent.Team:GetChildren() -- Looks for the children of "Team" group for i, #P do -- This part I'm not sure if it works or not P.BrickColor = BrickColor.new(Color.Value) wait() end
Your code was just about right except two parts of it. When you use this method your going through a table of objects. So P is considered a table, and "i" is the loop (count). In tables there are numbered objects.
Example: P[1]
So when using this method you want to do P[i]. Also you want to do "for i = 1,#P". # means "Number" basically.
http://wiki.roblox.com/index.php?title=Table
local Color = script.Parent.TeamColor local P = script.Parent.Team:GetChildren() for i = 1,#P do --Use "for i = 1,#P do" P[i].BrickColor = BrickColor.new(Color.Value) --Don't forgot P[i] wait() end
UndiscoveredLimited's answer was more sufficient, I thought it was gone, but I guess it's not so I will just keep what I just edited. If you don't understand what for _ ,v in pairs(EXAMPLE:GetChildren()) do
means then I suggest you take a look at the link below. Its the best that I could find in a flash.
local Color = script.Parent.TeamColor for _,v in pairs(script.Parent.Team:GetChildren()) do --This is more sufficient! v.BrickColor = BrickColor.new(Color.Value) wait() end
http://wiki.roblox.com/index.php?title=Function_dump/Basic_functions#pairs
I hope you understand it better now.
Locked by BlueTaslem
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?