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.
local on = false script.Parent.MouseButton1Down:Connect(function() on = true end) script.Parent.MouseButton1Up:Connect(function() on = false end) while wait() do while on == true do -- Count time end end
local timer = 0 local on = false script.Parent.MouseButton1Down:Connect(function() on = true end) script.Parent.MouseButton1Up:Connect(function() on = false end) while on do--works while on is true wait(0.1)--waits the amount of time timer = timer + 0.1--adds on the wait value onto the timer end