What do you want to achieve? Keep it simple and clear!
I want to make it so that, after a period of time, if the mouse is not clicked a certain value will be set to false. If the mouse is clicked, then it will carry on with the script.
What is the issue? Include screenshots / videos if possible!
The issue is that I can’t figure out how to do it. I’ve tried wait() and tick() but neither of them are really ‘stable.’
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
After reading and searching for answers, I don’t see any functions or code examples on the DevHub, DevForum or Scripting Helpers that can do what I need (other than mouse.Idle; however, that’d require the mouse not to move, and I just need mb1 clicks).
Example Script:
local clicksInARow = nil --Let's say this has a cooldown where if the mouse isn't clicked for a second, it resets
UIS.InputBegan:Connect(function(input,gameProcessed)
if gameProcessed then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
clicksInARow = clicksInARow + 1
--(insert code here)- detects if the mouse is not clicked after a period of time, then it resets
end
Extra Info:
What I am trying to achieve is a basic m1 feature from games like Grand Piece Online, Anime Dimensions, things like that if you’re familiar with them. When you click it punches, kicks, etc, and unless you click again fast enough then it cancels and the counter resets, making it so that when you click again it starts from 0 instead of the last punch you performed. If you think I’m going about this the wrong way please let me know as I’ve never done something like this before and wanted to try it out.
local clicked = false
local seconds = 20
UIS.InputBegan:Connect(function(input,gameProcessed)
if gameProcessed then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
clicked = true
end
end)
while wait(seconds) do
if clicked == true then
-- do stuff if player hasn't clicked
else
-- do other stff if player HAS clicked
end
Maybe I am being silly, but I don’t think this will work. It’s my fault, I didn’t give enough detail. What I am trying to achieve is a basic m1 feature from games like Grand Piece Online, Anime Dimensions, things like that if you’re familiar with them. When you click it punches, kicks, etc, and unless you click again fast enough then it cancels and the counter resets, making it so that when you click again it starts from 0 instead of the last punch you performed. I might be wrong thinking that it doesn’t apply to my current script, but I don’t think it does. While (or if) you reply I’ll attempt to implement it.
You can have a variable lastClick and store os.time() in it whenever a player clicks. Then, os.time() - lastClick will be the seconds since the last click.
you can then check if its been more than maybe a second or two you can reset the counter.
something like:
local clicks = 0
local cooldown = 1 --seconds after which the count resets
local lastClick = os.time()
UIS.InputBegan:Connect(function(input,gameProcessed)
if gameProcessed then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if os.time()-lastClick >= cooldown then -- if currentTime - lastClick is greater than cooldown (1 second) then reset counter
clicks = 0
end
lastClick = os.time() --save the current time in lastClick variable
clicks += 1 --increment clicks by one
end
end)
After testing it, the only problem with it is it resets always after 1 second regardless of whether or not you’re spam clicking, which I’m not sure why that is…