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

Part follow mouse? [closed]

Asked by
k1nq 30
8 years ago

So, I was trying to make a tool that when you chose a certain thing, such as a part, it would show up and follow mouse, then once you click it would place it, how could I do this?

Closed as Not Constructive by Shawnyg, AwsomeSpongebob, and rexbit

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 8 years ago

Well, if you want a simple way to make a part follow the player's mouse you can do this:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local part --= whatever part you want to move

local render = game:GetService("RunService").RenderStepped

local moving
local function movePart(currentPart)
    moving = true
    render:connect(function()
        if moving then
            currentPart.CFrame = CFrame.new(mouse.Hit.p)
        end
    end)
end

movePart(part) --you can call this whenever you want to move another part

mouse.Button1Down:connect(function()
    moving = false --stops moving the part
end
Ad