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 4 years ago
Edited 4 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:

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!

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

1 answer

Log in to vote
1
Answered by
piRadians 297 Moderation Voter
4 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 — 4y
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 — 4y
Ad

Answer this question