How do i get the player's mouse position

Hi im new to the local player mouse and im having trouble getting the position of the mouse could i get some help?

3 Likes

Google google google. Get Mouse Mouse X

2 Likes

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

print(mouse.Hit)

or print(mouse.Hit.p)

I think.

3 Likes

You can get a mouse position, like this:

local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()

Mouse.Move:Connect(function()
    print("Mouse position is "..Mouse.Hit.p)
end)
17 Likes
-- in a localscript
local Player = game:GetService('Players').LocalPlayer
local Mouse = Player:GetMouse()

game:GetService('UserInputService').InputBegan:Connect(function(i,o)
    if o then return end
    if i.UserInputType == Enum.UserInputType.MouseButton1 then
        local MousePos = mouse.Hit.p
        print(MousePos)
    end
end)
5 Likes

thats really helpful but i am trying to put teleport and i dont want the player to teleport in the air so how would i fix this

You can use either math.clamp or raycast.

1 Like

Check if Mouse.Target:IsA("BasePart")

1 Like