This is for a gun I'm making, but I want it to be an automatic rifle, as in it will keep shooting if you hold it down.
But I don't know how to tell if someone is.
Is there like an event or something to tell?
This is for a gun I'm making, but I want it to be an automatic rifle, as in it will keep shooting if you hold it down.
But I don't know how to tell if someone is.
Is there like an event or something to tell?
I use something like this: Basically you need to spawn a loop that checks if a variable called "MouseDown" is true, and when the mouse event Button1Down is called, set the variable to true, but when Button1Up is called, set the variable to false.
As long as this is in a local script it will work.
EDIT: Added a renderstepped wait to the loop
local player = game.Players.LocalPlayer;
local Mouse = player:GetMouse();
local MouseDown = false;
local rs = game["Run Service"].RenderStepped; -- Faster loop
function MouseChecker()
while true do
rs:wait();
if (MouseDown == true) then
print("Mouse is down");
-- repeat code here while the mouse is down
end
end
end
Mouse.Button1Down:Connect(function()
MouseDown = true;
end)
Mouse.Button1Up:Connect(function()
MouseDown = false;
end)
spawn(MouseChecker);
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
For future reference, it'd be better to integrate your "MouseChecker" in a run service step update, rather than an ongoing loop. I'd suggest using BindToRenderStep, with the Input render priority value.
Yeah, I know there are more efficient & responsive ways to do it but I wasn't really focusing on maximum efficiency, it was more of an example solution.