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

LocalScript setting brickcolor based on brickcolorvalue does nothing? [CLOSED]

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!

1 comment

0

Take it off the workspace and redeclare the variables.

1 answer

✓ Accepted answer

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.

2 comments

0

Ah. Does a folder work, though? that is what I was using.

0

Nevermind. This isn't the answer i was looking for because i think there was a studio bug with the size of the file but i will accept because this is great to know :)

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