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

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

Asked by 9 years ago

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

1 answer

Log in to vote
5
Answered by 9 years ago

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
0
Not really sure how to put it... But thanks, I guess? CosmicHaze 0 — 9y
Ad

Answer this question