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

How can I make something that changes when you click it two times?

For example, I have a brick that when you click it once, the color is red, you click it a second time and it's yellow, a third time it's blue and the fourth time it goes back to red and the cycle repeats. How can I archieve this?

4 answers

As Ponytails2017 said, this is not a request site. As you did make an effort to post your attempts, I am happy to help. Just remember in the future to follow the guildelines.

local clickDetector = script.Parent -- instance of ClickDetector
local uses = 0

clickDetector.MouseClick:Connect(function(player)
	uses = uses + 1
	if uses == 1 then
		clickDetector.Parent.BrickColor = BrickColor.new("Bright red")
	elseif uses == 2 then
		clickDetector.Parent.BrickColor = BrickColor.new("Baby blue")
		uses = 0 -- reset the count after the 2 clicks to continue checking
	end
end)

You should check this out for more information: ClickDetector API

EDIT

I noticed I forgot to change 'script.Parent.BrickColor' to 'clickDetector.Parent.BrickColor'. It has been fixed.

3 comments

0

Not requesting a script, just saying how could I archieve something like this.

0

Doesn't work when I apply it to my script.

1

Revisions have been made.

write a variable called uses or something

local uses = 0
if uses == 1 then
uses += 1
(change color here)
elseif uses == 2 then
uses += 1
(change color here)
elseif uses == 3 then
uses += 1
(change color here)
end

-- and repeat, inset this inside of the click detector function

2 comments

0

remove the "(change color here)", youre supposed to place the code to change where it says to

0

Doesn't work.

Tried to make it myself, but this doesn't work still.

while wait(1) do
	local value = 0
	if value == 0 then
		script.Parent.BrickColor = BrickColor.new("Bright red")
		value = value + 1
	end
	if value ==  1 then
		script.Parent.BrickColor = BrickColor.new("Bright yellow")
		value = value + 1
	end
	if value == 2 then
		script.Parent.BrickColor = BrickColor.new("Baby blue")
		value = value - 1
	end
end

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