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

Part follow mouse?

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?

1 answer

✓ Accepted answer

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

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