How to make a part move with your mouse

 
--- This Will Only Work In A Local Script

local mouse = game.Players.LocalPlayer:GetMouse() --- Gets Players Mouse

--- Now we want to print the position 

local x,y,z = mouse.Hit.X,mouse.Hit.Y,mouse.Hit.Z 

print(x,y,z)

---Output: Xpos,Ypos,Zpos

Now lets make a part move with the players mouse.

local RunService = game:GetService ("RunService")

 local newpart = instance.new("Part",game.Workspace) ---Creates new part

newpart.Size = Vector3.new(5,5,5) ---Self explanatory 

local mouse = game.Players.LocalPlayer:GetMouse() --- Gets Players Mouse

local x,y,z = mouse.Hit.X,mouse.Hit.Y,mouse.Hit.Z 

--- Mouse.Target tells you what base part your hovering

if mouse.Target == newpart then --- checking if the mouse is hovering the part
 RunService.RenderStepped:Connect(function() --- A friendlier while true do

newpart.Position = Vector3.new(x,y/game.Workspace.Baseplate.Postion,z)


   end)

end


You can also view here: Mouse-Properties/How to make a part move with players mouse at main · TinyFlair/Mouse-Properties · GitHub

9 Likes

One way i can think of is using the Moust.Hit property which is the CFrame of where the mouse is pointing to in the game space. you could also use this along with UserInputService.InputBegan event to detect when the mouse moves that way you dont check in every single frame.

Edit: wait im dumb you already did use Mouse.Hit
Edit2: I’m even more dumb, this is a tutourial LOLOL

1 Like

Ahh okay I understand, not but fr how did u find this :skull:

1 Like

I was just on the New section and just read the topic without looking at the category. Lesson learned

1 Like