I have created a script that makes a part follow the mouse. I have made a part follow the mouse with BodyPosition and not by changing it’s CFrame/Position. I want to know why it goes so far back when I put my mouse into the skybox. Here is my script:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local down = false
local target
mouse.Button1Down:Connect(function()
down = true
if mouse.Target and mouse.Target:FindFirstChild("Grabbable") and mouse.Target:FindFirstChild("Grabbable").Value == true then
target = mouse.Target
local bp = Instance.new("BodyPosition", mouse.Target)
bp.MaxForce = Vector3.new("inf", "inf", "inf")
bp.D = 1500
bp.P = 2500
bp.Position = mouse.Hit.p
mouse.TargetFilter = target
end
end)
mouse.Move:Connect(function()
if target and down then
target.BodyPosition.Position = Vector3.new(mouse.Hit.X, mouse.Hit.Y, mouse.Hit.Z)
end
end)
mouse.Button1Up:Connect(function()
mouse.TargetFilter = nil
target.BodyPosition:Destroy()
target = nil
down = false
end)
Can somebody please help me with this?