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

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

Asked by 4 years ago
Edited 4 years ago

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

2 answers

Log in to vote
0
Answered by
SmartNode 383 Moderation Voter
4 years ago

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
0
Unless you want to do it locally. DeceptiveCaster 3761 — 4y
0
You could if you didn’t want it to replicate. SmartNode 383 — 4y
Ad
Log in to vote
0
Answered by
BiIinear 104
4 years ago

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

0
Thanks, it helped a lot! ModernFilms 5 — 4y

Answer this question