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

How do I make it so when you press a button it toggles a part to change color?

I have tried many scripts, but none of them work. Im not that good at making scripts so help would be nice!

2 answers

There are three things I’m assuming:

  • the button is a clickable UI object
  • you clearly aren’t familiar with remote events
  • you also aren’t familiar with this sites rules.

Never the less, I’ll still help you lol..

  • create a remote event
  • fire the remote event from the client when the button is pressed
  • listen to the fire on the server and change the parts color from there

2 comments

0

Unless you want to do it locally.

0

You could if you didn’t want it to replicate.

There are two simple ways of doing this.

This code changes color if the button and part are inside a model.

model = script.Parent

model.Button.ClickDetector.MouseClick:Connect(function()
model.ColorPart.BrickColor = BrickColor.new("Lime green")
end)

This code changes color if the part is somewhere in workspace.

part = workspace:FindFirstChild("ColorPart")
button = script.Parent

button.ClickDetector.MouseClick:Connect(function()
part.BrickColor = BrickColor.new("Lime green")
end)

I hope this answers your question! If you are experiencing any problems, comment back. This was actually one of my first successful scripts I've made back in 2017 lol

1 comment

0

Thanks, it helped a lot!

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