Edit: Closed because for some reason it started working after making no changes whatsoever. Bizarre, but glad it is working now?
Hello!
In my game I need to set the color of multiple parts based on a random BrickColorValue which is sharing the same parent as the localscript. It is a simple script, and should be working, but there are no errors and nothing happens.
The code:
local val = script.Parent.treeType val.Value = math.random(1,5) local val2 = script.Parent.leafColor val2.Value = BrickColor.Random() local val3 = script.Parent.trunkColor val3.Value = BrickColor.Random() local children = workspace.Model.Tree1:GetChildren() for i, child in ipairs(children) do if child.Name == "Leaves" then child.BrickColor = val2.Value end if child.Name == "Trunk" then child.BrickColor = val3.Value end end
I apologize if the error is simple and I just missed it. This is honestly quite weird for me.
Thanks!
From the lua wiki:
A LocalScript will only run Lua code if it is a descendant of one of the following objects:
• A Player’s Backpack, such as a child of a Tool
• A Player’s character model
• A Player’s PlayerGui
• A Player’s PlayerScripts.
• The ReplicatedFirst service
Otherwise it won't run at all. I'd recommend placing it under PlayerScripts and redeclaring your variables.