Why is the elseif statement not working

so i am trying to make a part which would change color when you click on it, and when you click on it again, it would change back to its original color, but the elseif statement which i did there which would change the part back to the original color won’t work at all. the other blocks of code work properly, but the elseif statement doesn’t seem to be running at all

try

local part = script.Parent
local bool = false

part.ClickDetector.MouseClick:Connect(function()
if not bool then
part.BrickColor = BrickColor.new(“Black”)
bool = true
else
part.BrickColor = BrickColor.new(“White”)
bool = false
end
end)

local bool = false
script.Parent.ClickDetector.MouseClick:Connect(function(player)
	if bool == false then
		script.Parent.BrickColor = BrickColor.new("Black")
		bool = true
	elseif bool == true then
		script.Parent.BrickColor = BrickColor.new("White")
		bool = false
	end
end)
Well its working for me

example
image

Maybe elseif statement works but it changes part color to white similar as default part color (dark stone gray) so you got confused?

1 Like

You can replace the elseif bool == true with else because in this case bool can only be true or false.

Its the same thing, I’ve just corrected his code I didn’t rewrite it.

local part = script.Parent
local click = part.ClickDetector

local bool = false

click.MouseClick:Connect(function(player)
	bool = not bool
	part.Color = if bool then Color3.new(1, 1, 1) else Color3.new(0, 0, 0)
end)
1 Like