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 4 years ago
Edited 4 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.

1local Players = game:GetService("Players")
2local Player = Players.LocalPlayer
3local Mouse = Player:GetMouse()
4local Pos = Vector3.new(Mouse.Hit.Position())
5 
6print(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 — 4y
0
I mean the position of the mouse in the 3D world Kilonove 7 — 4y

1 answer

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

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

01local Pos = nil
02local Mouse = game.Players.LocalPlayer:GetMouse()
03 
04local function check()
05    Pos = Mouse.Hit.Position
06    print(Pos)
07end
08 
09-- while true do
10--  check()
11-- wait(0.1)
12--  Delete the comments if you want to test if this works.
13-- end
0
I'm pretty sure that worked, Thanks! Kilonove 7 — 4y
Ad

Answer this question