Hello, so I am trying to make something in a tool that tells you for how long the left mouse button was pressed. The only idea I could come up with was to make a loop that activates on the Mouse.Button1Down event and counts in 0.1 seconds. Then I would break that loop and just use the information that I got in the Mouse.Button1Up part. However I can't break the loop. So, any better ways of doing this or just a way to break the loop when the left button goes up?
xXTouchOfFrostXx answered your question.
01 | local on = false |
02 | script.Parent.MouseButton 1 Down:Connect( function () |
03 | on = true |
04 | end ) |
05 |
06 | script.Parent.MouseButton 1 Up:Connect( function () |
07 | on = false |
08 | end ) |
09 |
10 | while wait() do |
11 | while on = = true do |
12 | -- Count time |
13 | end |
14 | end |
01 | local timer = 0 |
02 | local on = false |
03 | script.Parent.MouseButton 1 Down:Connect( function () |
04 | on = true |
05 | end ) |
06 |
07 | script.Parent.MouseButton 1 Up:Connect( function () |
08 | on = false |
09 | end ) |
10 |
11 | while on do --works while on is true |
12 | wait( 0.1 ) --waits the amount of time |
13 | timer = timer + 0.1 --adds on the wait value onto the timer |
14 | end |