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

How can I cause a Part to follow the cursor?

Asked by 7 years ago

I made an attempt to accomplish this:

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

while true do
    local bob = game.Workspace.Bob
    bob.Position = Vector3.new(mouse.Hit)
end

I read that you need to use Mouse.Hit for it's position but I am probably wrong. What's the proper way to get the position of the mouse?

1 answer

Log in to vote
0
Answered by 7 years ago

mouse.Hit will return the mouse's CFrame, you need to add a .p to mouse.Hit to get the position like so, mouse.Hit.p, or you could just change bob's CFrame, instead of Position.

local plr = game.Players.LocalPlayer
local m = plr:GetMouse()

game:GetService("RunService").RenderStepped:Connect(function()
    local bob = workspace.Bob
    if bob then
        bob.CFrame = m.Hit
    end
end)
0
Thanks, and the RenderStepped is a good idea. I didn't think of that at the time. WillContinues 20 — 7y
0
Yeah man. If I helped you, please accept this as an answer <3 AlreadyPro 153 — 7y
0
It didn't work. I tried switching from CFrame = m.Hit to Position = m.Hit.p and same result WillContinues 20 — 7y
0
It works for me... AlreadyPro 153 — 7y
View all comments (2 more)
0
Use GetService("Mouse").Move instead of RenderStepped. IcedVapour 153 — 7y
0
Nevermind, it works. My studio was just bugging out. WillContinues 20 — 7y
Ad

Answer this question