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

Does anyone know how to make a part follow your mouse cursor? And where to put it in the script?

Does anyone know how to make a part follow your mouse cursor? And where to put it in the script?

1 answer

You weren't very specific and this isn't a request site, use a local script in player gui, get the player's mouse, set the cframe of the part to constantly update using a loop to the .Target of the player's mouse (mouse.Hit). Not very descriptive question = not very descriptive answer.

Fine, because I'm feeling nice, I'll tell you! Here's the code that should go in a local script in StarterGui, but this is only basic and will be a bit glitchy.

plr = game.Players.LocalPlayer
mouse = plr:GetMouse()
repeat wait() until plr.Character
p = Instance.new("Part",game.Workspace)
p.Anchored = true
repeat wait() until mouse.Hit ~= nil and mouse.Target ~= nil and mouse.Target ~= p
p.CFrame = mouse.Hit*CFrame.fromEulerAnglesXYZ(math.rad(0),math.rad(0),math.rad(0))
p.CFrame = p.CFrame+Vector3.new(0,0.5,0)

while wait() do
	if mouse.Hit ~= nil and mouse.Target ~= nil and mouse.Target ~= p then
		p.CFrame = mouse.Hit*CFrame.fromEulerAnglesXYZ(math.rad(0),math.rad(0),math.rad(0))
		p.CFrame = p.CFrame+Vector3.new(0,0.5,0)
	end
end

1 comment

0

Not really sure how to put it... But thanks, I guess?

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