Still have questions? Join our Discord server and get real time help.
1

# Moving a part to mouse position?

zblox164 485
1 year ago

So I need to make a part follow the mouse for my games. Is there a simple way to move a part depending on the position of the mouse? I have tried using the events and functions that the mouse object has but have failed each time. I am using a local script that is in StarterGui and the part is in workspace. Anyway here is the code I am trying to use.

I could easily be doing this completely wrong but here's my attempt:

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

Mouse.Move:connect(function() -- When the mouse moves it triggers the function
game.Workspace.Part.Position = Vector3.new(Mouse.Target) -- This is my error
end)


On line 5 I also tried using Mouse.Hit, Mouse.TargetFilter, Mouse.X and Y, And the rest of the properties that had to do with the position of the mouse. I could have missed one so here is the link to the page I am looking at:

https://wiki.roblox.com/index.php?title=API:Class/Mouse

Thanks for the help!

0
Doesn’t Mouse.Target get the part the mouse is on and not the position of it? I don’t know, I got this info from the wiki. Denny9876 1292 — 1y
0
Just checked and yes you are correct. Then my question would be how to get the position of the mouse cause that I have no idea. zblox164 485 — 1y
1
Denny9876 1292 — 1y
0
Yep this is what I need! Thanks for the help zblox164 485 — 1y
0
I got it to work zblox164 485 — 1y