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

How do I change the color of a part I made using the Instance() function with a ClickDetector event?

``Part = Instance.new("Part", game.Workspace)

Part.Position = Vector3.new(0, 0, 0)

game.Lighting.ClickDetector.Parent = Part

game.Workspace.Baseplate.Part.ClickDetector.MouseClick:connect(function()

Part.BrickColor = BrickColor.new("Lavender")

end)``

What im trying to do : make a part using instance function, and then click on the part to change its color.

1 answer

✓ Accepted answer

Instead of doing that, you should do this;

local Part = Instance.new("Part", workspace)
local Bc = BrickColor.new("Lavender")
Part.Position = Vector3.new(0, 0, 0)

game.Lighting.ClickDetector.Parent = Part

game.Lighting.ClickDetector.MouseClick:connect(function()

Part.BrickColor = Bc

end)

So it's more reliable using local variables than normal ones. Plus the brick color gotta be in a variable. Plus, you can't change the parent in a script, then get the parent in the script. It's because that you changed it in the script, not the game itself. Plus, scripts only run when you playtest/play, so it won't have the effect of the parent being changed until the game is started. that's why it didn't work. Copy the script above, and it might work.

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