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

How to make a Part change color on a click of a SurfaceGUI?

I am very new to scripting, and I have played LBP2, and LBP3 and the Techno seems so simple. But Roblox's LUA seems so difficult. I want to make a little booth, where you click a SurfaceGUI of a certain color, and many parts turn colors. For example, a player hits a Blue SurfaceGUI, then 10 blocks infront of the player turns Blue. Or a player hits a SurfaceGUI and bricks infront of him turn random. I do got an idea on what to do, but I need help on the Click thing. Here is what I would do. Just tell me if I do anything wrong. Can you help me?

if (Something where a player hits a SurfaceGUI) then Game.Workspace.DanceFloor.Part1.BrickColor = ("Toothpaste")

But I want it to also work on multiple parts.

I tried using:

function color()
Game.Workspace.Part.BrickColor = ("Toothpaste")
end

script.Parent.MouseButton1Down:connect(color)

But i get the error:

"Workspace.ColorThePart.SurfaceGui.TextButton.Script:2: bad argument #3 to 'BrickColor' (BrickColor expected, got string)"

Can someone help me with this??

1 comment

0

Like in the answer bellow, you need to change colors by setting the parts BrickColor = to "BrickColor.new("ColorNameHere")

2 answers

✓ Accepted answer

If I understand your question correctly, What you're trying to do is change the colour of some blocks when a surface GUI is clicked.

function onClick(clicked) -- This makes the rest of the code run when it's clicked
	game.Workspace.DanceFloor.Part1.BrickColor = BrickColor.new("Toothpaste") -- What you want to happen
script.Parent.MouseButton1Down:connect(clicked) -- Connection line

I believe what you're missing is the BrickColor.new If this doesn't answer your question fully, or you don't understand please do reply or send me a PM :) But if it does answer your question don't forget to accept my answer :)

1 comment

0

Thanks! There was a glitch though, when I clicked the GUI, nothing happened, because when I went to test it, the BrickColor already turned the color "Toothpaste", but I get what you are trying to say.

Nevermind, I found a way to do it! Just put this into a brick! Also, thanks to everyone who helped me with my little flaw. :)

function color()
Game.Workspace.Part.BrickColor = BrickColor.new("Toothpaste")
end

script.Parent.MouseButton1Down:connect(color)

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