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

How do I use my while loop properly?

Asked by 6 years ago

Ok so I made a gun, semi auto works perfectly. I went into trying to make a full auto gun, it works except it doesn’t stop shooting. I am using Mouse.Button1Down I did ~~~~~~~~~~~~~~~~~while Mouse.Button1Down do shoot() wait(.2) end~~~~~~~~~~~~~~~~~

Can anyone tell me how to make it so it only shoots when the left button is down and it stops shooting when I stop holding down the button?

Thanks

1 answer

Log in to vote
1
Answered by
EgoMoose 802 Moderation Voter
6 years ago

Mouse.Button1Down is an event. This means it will fire a function when the mouse button is pressed down. It does not return a boolean value of true or false. You want to make it so that a boolean variable is updated when the mouse is pressed down (or up) and then you can structure your code in a while loop like you have.

This is probably more along the lines of what you want:

local isButton1Down = false;

mouse.Button1Down:connect(function()
    isButton1Down = true;
end);

mouse.Button1Up:connect(function()
    isButton1Down = false;
end);

while (isButton1Down) do 
    shoot();
    wait(.2);
end;
0
or, y'know. UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) creeperhunter76 554 — 6y
Ad

Answer this question