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

Repeatedly firing function when mousebutton1 is holding? [closed]

Asked by
Netflixy 126
8 years ago

This question already has an answer here:

When mouse is HOLDING?

How can I fire a function repeteadly while mousebutton1 is holding down, and stop it when it stops to be holden?

I've tried a few thing, none working.

Sorry about the grammar mistakes :P

Marked as Duplicate by Shawnyg

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?

1 answer

Log in to vote
0
Answered by
ausmel105 140
8 years ago

First of all, make sure you're using a Local Script.

This code should work:

local mouse = game.Players.LocalPlayer:GetMouse()
local mousdwn = false

Mouse.Button1Down:connect(function()
    mousdwn = true
    spawn(function() Mouse.Button1Up:wait() mousdwn = false end)
    while mousdwn do
        -- recurring code
        wait()
    end
end)

EDIT: Almost gave you the loop of death. :P

Ad