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

Help me fix a simple recoloring script?

Asked by 5 years ago
Edited by User#5423 5 years ago

--I'm trying to create a script that will allow me to recolor a lot of parts, meshes, and unions within a model. I'm very amateur at scripting and could anyone help me fix this script?

Here's my code. Chest is the name of the model. lua if game.Workspace.Chest.Child.BrickColor = ('Dark stone grey') then BrickColor = ('Hot pink') Output says Workspace.Script:1: 'then' expected near '='

Would appreciate any help.

0
pls use code block User#5423 17 — 5y
0
= is an assignment operator. == is the comparison logic operator. The error is explaining it expected then aftern the logic but got an assignment operator. User#5423 17 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

General Practice

Use workspace instead of game.Workspace

Use :WaitForChild() to make sure something exists before using or changing it

Issues

For if-then statements, if you want to make sure a property equals an assigned property, you need to make sure you use two equal signs ("==" instead of "=") since otherwise you are trying to assign a property, rather than comparing them

When you need to check a BrickColor, you must use BrickColor.new() before the name of the color since BrickColor is a type of property, not a string value.

Revised Code

if workspace:WaitForChild("Chest"):WaitForChild("Child").BrickColor == BrickColor.new("Dark stone grey") then
    BrickColor = BrickColor.new("Hot pink")
Ad

Answer this question