I am having trouble with this and I know it's a simple script but I can't find any answers out there. I would like to learn from this. Thank you.
mouse = game:GetService("Players").LocalPlayer:GetMouse() mouse.Button1Down:Connect(function() -- skript here end)
for up use
mouse = game:GetService("Players").LocalPlayer:GetMouse() mouse.Button1Up:Connect(function() -- skript here end)
Remember it needs to be local script I hope this helps.
Utilize the Button*Down/Up methods on the Mouse, obtained by calling :GetMouse() on the LocalPlayer object.
local mouse = game.Players.LocalPlayer:GetMouse();
With this function, we can check if the Button1Down is fired.
local Mouse = game:GetService('Players').LocalPlayer:GetMouse(); local BeingHeldDown = false; Mouse.Button1Down:Connect(function(DownFunction) BeingHeldDown = true; end) Mouse.Button1Up:Connect(function(UpFunction) BeingHeldDown = false; end);
If we use a variable to remember the state of the mouse, this will allow us to check if the player is holding down the left mouse button. This will allow us to do cool loops like this:
while BeingHeldDown do wait() print('Mouse is being held down!') end
or something like this:
game:GetService('UserInputService').InputBegan:Connect(function(Key, Process) Key = Key.KeyCode -- I don't need anything else that Key provides if (Key == Enum.KeyCode.E) and BeingHeldDown then print('The E button is being pressed while the MouseButton1 is being held.') end end)
Using variables to log event states can prove to be very useful in many cases.