Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Moving a part to mouse position?

Asked by
zblox164 531 Moderation Voter
6 years 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. User#20279 0 — 6y
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 531 — 6y
0
Yep this is what I need! Thanks for the help zblox164 531 — 6y
0
I got it to work zblox164 531 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

is it something like this? https://www.roblox.com/library/835627796/Grabbable

0
Yes zblox164 531 — 6y
Ad

Answer this question