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

Grabbing Position from Mouse.Hit()?

Asked by 3 years ago
Edited 3 years ago

Hi all!

Im using this script I clobbered together by looking at Mouse on the wiki and some stuff from here. I havent really used this before so I'm not even sure if this is really correct but I cant print Pos from here.

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local Pos = Vector3.new(Mouse.Hit.Position())

print(Pos)

I'm trying to get a mouse position, then convert it so a NPC can move to it. I may just be extremely dumb. I'm newer to scripting so please go easy on me.

0
By mouse position do you mean the Vector3 position of where the mouse is pointing or the Vector2 position of where it is on the screen? poptartisfemboy -4 — 3y
0
I mean the position of the mouse in the 3D world Kilonove 7 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Apologies, it seems I misunderstood again. Here is some code.

local Pos = nil
local Mouse = game.Players.LocalPlayer:GetMouse()

local function check()
    Pos = Mouse.Hit.Position
    print(Pos)
end

-- while true do
--  check()
-- wait(0.1)
--  Delete the comments if you want to test if this works.
-- end
0
I'm pretty sure that worked, Thanks! Kilonove 7 — 3y
Ad

Answer this question