Help with getting the mouse

i want to make it so when the mouse get close to the player it will move the player to the direction the mouse looking at

1 Like

You can get the position of the mouse in workspace and teleport the player to it, I’m not sure about the part when it checks if it’s close to the player

-- local script in StarterCharacterScripts
local plr = game.Players.LocalPlayer
local char = script.Parent
local mouse = plr:GetMouse() -- mouse

mouse.Move:Connect(function() -- detect when mouse moves
local mousePos = mouse.Hit -- get mouse position in 3d space
char:SetPivot(mousePos) -- move character to that position
end)
1 Like

ok but leme try this real quick

its a local script inside of starter player scripts right?

…please read the code carefully before asking

ow lol i didnt saw that
and i love pizza

but there is an error beacuse its telling the character to go to the mouse(SetPivot is not a valid member of Model “Workspace.harelnave123”)

In the mouse pos you should do hit.Position not just hit

local plr = game.Players.LocalPlayer
local char = script.Parent
local mouse = plr:GetMouse() – mouse

mouse.Move:Connect(function() – detect when mouse moves
local mousePos = mouse.Hit.Position – get mouse position in 3d space
char:SetPivot(mousePos) – move character to that position
end)

i did but its still showing the error

local plr = game.Players.LocalPlayer
local char = script.Parent
local mouse = plr:GetMouse() – mouse

mouse.Move:Connect(function() – detect when mouse moves
local mousePos = mouse.Hit.Position – get mouse position in 3d space
char:SetPivot(mousePos) – move character to that position
end)

Try this code

no its still giving me the error "SetPivot is not a valid member of Model “Workspace.harelnave123"”

Then try

char:MoveTo(mousePos)

i think its crashing studio its saying gameplay paused

I meant char.Humanoid:MoveTo(mousePos)

its not teleporting to its moving towards the curser. what i meant is if i put my curser beside the player(at the left side) the player will go right

Ohhhh so you just want for it to kove to the left?

i thing so i love pizzaaaaaaaaa

So then you want to find whwt axia is the left, you can do that manually or use the cframe functions and only move in that axis