Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago
Edited 5 years ago

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:

01local val = script.Parent.treeType
02val.Value = math.random(1,5)
03local val2 = script.Parent.leafColor
04val2.Value = BrickColor.Random()
05local val3 = script.Parent.trunkColor
06val3.Value = BrickColor.Random()
07 
08local children = workspace.Model.Tree1:GetChildren()
09for i, child in ipairs(children) do
10    if child.Name == "Leaves" then
11        child.BrickColor = val2.Value
12    end
13    if child.Name == "Trunk" then
14        child.BrickColor = val3.Value
15    end
16end

I apologize if the error is simple and I just missed it. This is honestly quite weird for me.

Thanks!

0
Take it off the workspace and redeclare the variables. piRadians 297 — 5y

1 answer

Log in to vote
1
Answered by
piRadians 297 Moderation Voter
5 years ago

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.

0
Ah. Does a folder work, though? that is what I was using. proqrammed 285 — 5y
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 :) proqrammed 285 — 5y
Ad

Answer this question