I am making a thing in which the player's mouse hovers over something and I want a small GUI to go where the mouse is displaying some information. It works 100%, but I need to get the player's mouse position. Thx!
There's 2 possible answers. One preferred over the other.
*Option 1 is using UserInputService.
Option 2 is using the Player's Mouse.*
UserInputService
local UIS = game:GetService("UserInputService") local mousePos = UIS:GetMouseLocation()
This will return the position in offsetted pixels, not the location pointed in workspace.
Player's Mouse
local player = game:GetService("Players").LocalPlayer local mouse = player:GetMouse() local mouseX = mouse.X local mouseY = mouse.Y --// This will return the position in offsetted pixels, not the location pointed in workspace. local mousePosW = mouse.Hit.p or mouse.Hit --// Vector3 - CFrame --// The CFrame of the mouse’s position in 3D space local mousePosWW = mouse.Origin.p or mouse.Origin --// Vector3 - CFrame --//A CFrame positioned at the Workspace.CurrentCamera and oriented toward the Mouse's 3D position. --// This will return the position in workspace, not the location in offsetted pixels.
Hope this helped! Feel free to select this as an answer if this helped you!
I recommend doing more research on the Player's Mouse, very useful!
local mouse = game.Players.LocalPlayer:GetMouse() mouse.Move:Connect(function() wait() print(Mouse.X) print(Mouse.Y) end)
You can change the mouse.Move to whenever you want to get the players mouse position, and the print was just an example to show you where the players mouse is.