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

How would one find which direction the mouse is moving at a given time?

Asked by 7 years ago

I'm trying to figure out how to find the direction the mouse is moving, and eventually narrow it down to just four options; if the mouse is going up, going left, going right, or going down. Anyone have any ideas on how this might be possible?

1 answer

Log in to vote
0
Answered by 7 years ago

The easiest way to do this is like so,

-- This is in a LocalScript
wait();
local player = game.Players.LocalPlayer; -- Sets player to be the localplayer
local mouse = player:GetMouse(); -- Sets mouse as the players mouse

while player.Character:FindFirstChild("Humanoid").Health > 0 do -- Just a check to see if the player is alive
    print("Mouse X: "..mouse.X..", Y: "..mouse.Y); -- mouse.X and mouse.Y return the position on screen that the mouses cursor is pointing at
    wait(0.5); -- Just a wait so it's not constantly printing it out.
end;

This script will print out the mouses location on screen every half a second. Here is a link to the wiki article for the Mouse class. Hope this helps!

0
Well this did help, it didn't do what I needed it to but I was able to figure it out from here. Thanks! Toadboyblue 67 — 7y
0
That was the plan. ;) I didn't want to just give you the answer. I wanted you to mess around with stuff while having an outline of what you needed. MrLonely1221 701 — 7y
Ad

Answer this question