#What statement should I use
1 messages · Page 1 of 1 (latest)
task.wait(7) then change the color back to green
** You are now Level 2! **
the problem is, if i clicked the button many times, it would count from the first time the button turned red instead of the last time it turned red
I guess I wanna make a timer, everytime the button turns red, it will set a timer until 7 secs before it turns green again.
However if it becomes green before 7 sec, the timer resets.
One way to solve this is to make a variable that is increased as soon as the button is pressed, and create a new variable that you will compare it to after the 7 seconds to make sure it has not changed.
so if the variable has changed (meaning it was clicked) you will return instead of making it green
something like this
local timesClicked=0
script.Parent.ClickDetector.MouseClick:Connect(function()
-- change the color to either red or green as you were doing,
timesClicked+=1
if red then -- replace with proper if statement
local n=timesClicked
task.wait(7)
if timesClicked==n then
-- change the color back to green
end
end
end)
why
i think theres a better way
local lasttimeclicked = nil
...clicked:con(function)
lasttimeclicked = tick()
task.wait(7)
if lasttimeclicked - tick > 7 then
print("turning red")
end
end
u could use task.defer
task.delay
or whatever
it all works anyway
this also work
thank u guys!!