So I made a similar dragging system from the one in lumber tycoon 2.
I used some code from Heath Hasikins Video.
I showed my friend and for some reason he can see it when I drag an object.
This is the code(Code is very messy I still need to clean it up.):
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local DragBall = nil
local Grabbing = false
function addBodyPos(part)
local BodyPos = Instance.new("BodyPosition", part)
BodyPos.MaxForce = Vector3.new(1000000,1000000,100000)
BodyPos.D = 1000
BodyPos.P = 10000
local BodyGyro = Instance.new("BodyGyro", part)
return BodyPos
end
function weldBetween(a, b)
local Weld = Instance.new("ManualWeld", a)
Weld.C0 = a.CFrame:inverse() * b.CFrame
Weld.Part0 = a
Weld.Part1 = b
return Weld
end
function creatBall()
local ball = Instance.new("Part", workspace)
ball.Shape = "Ball"
ball.Name = "DragBall"
ball.BrickColor = BrickColor.new("Really blue")
ball.Material = Enum.Material.Neon
ball.Size = Vector3.new(0.5,0.5,0.5)
return ball
end
Mouse.Button1Down:Connect(function()
Grabbing = true
local Target = Mouse.Target
if Target then
local NewDragBall = creatBall()
NewDragBall.CFrame = Mouse.hit
DragBall = NewDragBall
local DragBallWeld = weldBetween(NewDragBall, Target)
local BodyPos = addBodyPos(DragBall)
while Grabbing == true do
local cf = CFrame.new(Player.Character.Head.Position, Mouse.hit.p)
BodyPos.Position = (cf + cf.LookVector * 10).Position
NewDragBall.BodyGyro.CFrame = CFrame.new(Player.Character.Head.Position, Target.Position)
wait()
end
end
end)
Mouse.Button1Up:Connect(function()
Grabbing = false
if DragBall then
DragBall:Destroy()
end
end)
I want to know why this happens.