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

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

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?

1 comment

0

Why did you ignore this good answer?

3 answers

✓ Accepted answer

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!

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.

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!

1 comment

0

Explain your code. This isn't worthy of acceptance.

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