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

I need help turning my Part green when i click it, and red if i click it again after that?

Asked by 4 years ago
Edited 4 years ago

So I'm trying to make like an Occupied, Vacant kind of thing but it wont work...

Here is my current script:

script.Parent.MouseButton1Click:Connect(function()
 if script.Parent.Parent.BrickColor == ("Lime Green") then
    script.Parent.Parent.BrickColor = BrickColor.new("Really red")
else
script.Parent.Parent.BrickColor = BrickColor.new("Lime Green")
    end

Workspace looks like this btw:

Part -> ClickDetector -> SwitchScript

Why won't the script work?

0
Why did you ignore this good answer? Ziffixture 6913 — 4y

3 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Hello.

There are a few errors you have made with your script. The very first error, is that you have used the wrong Click function for the ClickDetector. ClickDetectors use MouseClick instead of MouseButton1Click. Second error in your script is that you aren't getting the Part's colour correctly, and it should be done with a BrickColor.new("Lime green") instead. Make sure that Lime Green is spelt exactly as Lime green or else it won't work. The syntax should already fill it in for you when typing this.

So, now that we have gone through the errors of the script, we can apply these changes, and make this system work.

Click script (ServerScript)

local ClickDetector = script.Parent
local Part = ClickDetector.Parent

ClickDetector.MouseClick:Connect(function()
    if Part.BrickColor == BrickColor.new("Lime green") then -- green isn't capitalised
        Part.BrickColor = BrickColor.new("Really red")
    else
        Part.BrickColor = BrickColor.new("Lime green")
    end
end)

Hope this helps!

Ad
Log in to vote
0
Answered by 4 years ago

MouseButton1Click is an event of a TextButton. MouseClick is the event of a ClickDetector that fires when the mouse is clicked on the ClickDetector's parent.

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Try this script:

I fixed Bit Of Errors:

script.Parent.MouseClick:Connect(function()
       local colorpart = script.Parent.Parent
       if colorpart.BrickColor == BrickColor.new("Lime green") then
       colorpart.BrickColor = BrickColor.new("Really red")
       print("Successfully Changed the"..colorpart.Name.." Part Color!")
     else
       colorpart.BrickColor = BrickColor.new("Lime green")
       end
end)

Please give a soultion. if it worked!

I think you might learn from Others and this answer something!

0
Explain your code. This isn't worthy of acceptance. Ziffixture 6913 — 4y

Answer this question