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

How would I possibly access the coordinates of the mouse and print them?

Asked by 8 years ago

Alright so, sorry I am not offering a script because, I have no idea as to how I would do this I don't care how dull of an explanation you provide as long as it's anything about accessing the coordinates of the mouse and printing those coordinates. I would be very grateful if anyone could help me with this!

Thank you, KingLoneCat

1
mouse.X and mouse.Y are the on screen coords. And mouse.Hit is the CFrame of what the mouse is hitting in the workspace theCJarmy7 1293 — 8y

2 answers

Log in to vote
2
Answered by 8 years ago

I'm going to throw out an answer because I think I'm okay at using the mouse.

First off, you can only do this in a Local Script. I think you already know this but it's important to get this established.

Second, there are lots of things that your question could mean, so I'm going to go through most of the mouse properties.

Mouse.Hit

Mouse.Hit is a CFrame value of the exact point the mouse is targeting in the 3d world. This is used for a ton of things. You would get the mouse.Hit similar to so,

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

mouse.Hit -- Getting the CFrame of the mouse

Normally it would be best to hook this up to a loop or a mouse move event.

Mouse.Hit.p

This is like mouse.Hit, but instead of being a CFrame, it's a Vector3. To be exact, it's a Vector3 of the mouses position only. You would get this in about the same way as with the Mouse.Hit but with a p at the end.

Mouse.X, Mouse.Y

There is no mouse.Z, because this isn't a value from a Vector3 or something. This is the position of the Mouse on the screen. Because the screen is a two denominational object, there's only two coordinates. This is often used with GUIs and sometimes part rotation.

More info about mouse.X, mouse.Y.

I'm going more into this because I think this is what you want. To be exact, mouse.X will return the number of pixels the mouse is away from left side of the screen. mouse.Y returns the number of pixels the mouse is from the top of the screen.

You would get mouse.X and mouse.Y like this,

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local x = mouse.X
local y = mouse.Y

However, if you wanted to keep track of this using a print statement then you could do something like this,

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
mouse.Move:connect(function()
    local x = mouse.X
    local y = mouse.Y
    print(x,y)
end)

Hope I Helped a Little

Good Luck!

Ad
Log in to vote
2
Answered by 8 years ago

Alright so, normally you would detect mouse’s coordinates by just simply identifying the mouse from the player which you could easily do by doing the following:

local player = game.Players.LocalPlayer — Variable for the player
local mouse = player:GetMouse() — Identified the mouse with a variable for it.

Now that you’ve identified it you could simply print the coordinates, by doing the following:

print(“x coordinate for the mouse is ”..mouse.x..” y coordinate for the mouse is “..mouse.y)

Answer this question