Been learning for a day now, very simple code wont work

Okay so my goal was to learn about functions, parents and children, and variables.
This was my code :slight_smile:

 local function color()
	wait(0.5)
	game.Workspace.ColorChange = (BrickColor) BrickColor.new(0.9,0.2,0.6)
	wait(0.5)
	game.WorkspaceColorChange = (BrickColor) BrickColor.new(0.2,0.6,0.2)
end
color()
wait(2)
color()

i wanted the function to be called color and was supposed to change the color of my part, the error was

ColorChange is not a valid member of Workspace “Workspace”
the part is called ColorChange it’s not in a model or another part its just in workspace some please explain

you need to fix game.WorkspaceColorChange on line 5. You need a period after the workspace and before the ColorChange.
things as simple as spelling errors, forgetting punctuation, can cause a script to produce errors, which is why I recommend going back through your script after typing it up and looking for things you did wrong.

ah im not a good reader thats my bad, thank you for pointing it out ill remember to check that from now on

1 Like

i fixed that error but it still says my part isnt a valid member of the workspace, i’ve tried changing the name and it still doesn’t work

Hi @intqrn! You’re on the right track. In order to change the color of a Part you need to set it’s BrickColor or Color property. Properties of objects are accessed the same way you ascend and descend the hierarchy. To fix the code you’ve provided I might try something like this:

local function color()
    wait(0.5)
    game.Workspace.ColorChange.Color = Color3.new(0.9,0.2,0.6)
    wait(0.5)
    game.Workspace.ColorChange.Color = Color3.new(0.2,0.6,0.2)
end
color()
wait(2)
color()

This code assumes there is a Part named ColorChange located in the Workspace.
(And one small tip: In roblox, you can access the Workspace object with simply workspace instead of the longer form game.Workspace, both ways are totally fine to use, but the prior might save you a few keystrokes!)

so would this be correct then

local function color()
wait(0.5)
Workspace.MyPart.BrickColor = BrickColor.new(rgb)
wait(0.5)
Workspace.MyPart.BrickColor = BrickColor.new(rgb)
end
color()
wait (2)
color()
wait(2)


brick color being the variable im trying to change with the function
and im trying to make the code do “color()” then wait then repeat
just confirming if my way of writing the code will work so ofc i can do it in the studio when im trying to write code

thank you for simplfiying it for me i understand better now and my code worked :slight_smile: :+1:

Close, sorry if I have confused you, but if you want to get the Workspace just from a single variable it must be all lowercase like: workspace. The code you just sent has a capital ‘W’. There are many ways to create a BrickColor (which is what you are setting the property of MyPart to). BrickColors are limited compared to Color3, but typically if BrickColor is used, it is provided the name of the color you want it to be in the form of a string. Example:

workspace.MyPart.BrickColor = BrickColor.new("Dusty Rose")

oh i know but i use the rgb thing but the code did work so thank you very much im now going to go and try make my own killbrick since i understand a little bit more what im doing, :+1: