Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Repeatedly firing function when mousebutton1 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

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.