Does anyone know how to make a part follow your mouse cursor? And where to put it in the script?
COMMUNITY QUESTION
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
This discussion is preserved as it was. New answers, comments, and votes are closed.

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