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

How do I make it so when I click an part with a script inside of it, it will follow my mouse?

Asked by
chasedig1 115
7 years ago
Edited 7 years ago

I don't know how I would do this, I want it to be like when you grab a piece of dough in Work at a Pizza Place. When I click a part, I want it to follow my cursor until I click again. Any idea of how I could do this? This isn't a request, I genuinely don't know how to do this.

1 answer

Log in to vote
0
Answered by 7 years ago

Unsure if this works outside of studio. Requires a ClickDetector in the part.

01local detector = script.Parent.ClickDetector
02local following = false --Used to stop others from clicking
03local leader = nil  --Parent of mouse that clicked the detector
04local stopFunc = nil
05 
06local runService = game:GetService("RunService")    --Recommend this over while loops
07 
08function followPlayer()
09    local mouse = leader:GetMouse()
10    local hit = mouse.Hit
11    local yAnchor = leader.Character:FindFirstChild("HumanoidRootPart").Position.Y  --Prevents dough from bouncing towards the screen
12 
13    if hit then
14        script.Parent.Position = Vector3.new(hit.p.X,yAnchor,hit.p.Z)
15    end
View all 41 lines...
Ad

Answer this question