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

Moving a part to mouse position?

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!

5 comments

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.

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.

0

Yep this is what I need! Thanks for the help

0

I got it to work

1 answer

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