Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Grabbing Position from Mouse.Hit()?

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.

2 comments

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?

0

I mean the position of the mouse in the 3D world

1 answer

✓ Accepted answer

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

1 comment

0

I'm pretty sure that worked, Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.