What is the best way to handle mouse inputs?

I have this “heavy attack” i want to make. It last for 2.5 seconds, and it gives you a bodyvelocity following your mouse direction. If you are in the air, the velocity follows your mouse. If you are on the ground, it follow’s your character. How do I make it? Each time I try it ends with exhaust and lags my studio


UserInputService and ContextActionService are your best bets for handling the input.

As for actually processing the input, you don’t want to give the client control of how their character moves, so you’ll have to do some cross-server communication. Character models do behave differently with client-server replication compared to most other Instances and typically have a lot more control to prevent things like input latency, so be careful with this.

There’s a neat Humanoid property that tells you if a Humanoid is on the floor or not (if they aren’t, the material will be Enum.Material.Air) but you can use a Raycast and a magnitude tolerance check to achieve this as well.


Letting the client decide where it will go isnt a problem it cannot be exploited right?
Also so the server doesnt have to do everything which will prevent the server from lagging


The way I handled it was I fired a remote to the client, and each time the mouse changed it fired to the server. The problem with this is that I had no way of stopping the client from firing, so it infinitely lagged.

Yes, anything handled on the client can be exploited. And this is something simple for dashing, so it won’t lag

1 Like

warning: I think I misunderstood your post, but I’ll leave this here anyway

You can utilize the client’s mouse object as well as the UserInputService.

local uis = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()

local chargeSeconds = 2.5
local charged = 0

local function startCharge()
    for i = 1, 25, 1 do
        if not uis:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then break end
        charged += 0.1
    repeat task.wait(0.1) until not uis:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)
    if charged == chargeSeconds then
        --when firing, you might want to pass things like mouse.Hit and mouse.Target
        --because the server cannot access the client's mouse
    charged = 0


Hope this helps!

Like @Negativize said, you could use humanoid properties. Things like the humanoid’s state and floor material will be the most helpful here. As for following the user’s mouse, try using the Player:GetMouse() function and using Mouse.Target on that.

probably with Player:GetMouse() or with UserInputService.

Still wont make a big difference its just 2 studs forward it wont effect the anti cheat system

You did misunderstand my original post, but this has helped a lot with a problem I had! I had made a custom skill assignment system where you could assign different skills to different keys. A problem was that some of them were "chargable’. This has greatly helped me! Thank you

1 Like

You should be doing this on the client.
It is far too inefficient to constantly send mouse position data to the server, you should instead being doing this on the client, and use RunService.RenderStepped.

While it is true that anything done on the client can be exploited, you want to keep in mind that the client already has network ownership of the character. This means that exploiters have full control of their own character regardless.

Alright. Thank you for your opinion! So I would just handle all of it on the client, instead of the server right?

You may still want to fire a remote letting the server know that the player used the move.
It’s also a good idea to validate stuff like cooldowns on the server as well, but the moving of the character itself should be done on the client.