Still have questions? Join our Discord server and get real time help.
Log in to vote

Moving a part to mouse position?

Asked by
zblox164 485 Moderation Voter
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 = -- This is my error

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:

Thanks for the help!

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
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
Yep this is what I need! Thanks for the help zblox164 485 — 1y
I got it to work zblox164 485 — 1y

1 answer

Log in to vote
Answered by 1 year ago

is it something like this?

Yes zblox164 485 — 1y

Answer this question