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

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

Asked by
Rukreep 15
2 years ago

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

Log in to vote
3
Answered by
appxritixn 2235 Moderation Voter Community Moderator
2 years ago
Edited 2 years ago

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.

0
Not requesting a script, just saying how could I archieve something like this. Rukreep 15 — 2y
0
Doesn't work when I apply it to my script. Rukreep 15 — 2y
1
Revisions have been made. appxritixn 2235 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

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
0
remove the "(change color here)", youre supposed to place the code to change where it says to MacGames007 114 — 2y
0
Doesn't work. Rukreep 15 — 2y
Log in to vote
0
Answered by 2 years ago

This is not a request site dude, try it first then if it doesn't work we can help you. https://scriptinghelpers.org/help/community-guidelines

0
I'm not requesting a script. I am doing a building game and for the paint tool I want to implement this, but don't know how. Rukreep 15 — 2y
Log in to vote
0
Answered by
Rukreep 15
2 years ago

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

Answer this question