Advertisement
BobMe

PenthingLocal

Jul 1st, 2020 (edited)
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2. local cam = workspace.CurrentCamera
  3. local mouse = player:GetMouse()
  4. local us = game:GetService("UserInputService")
  5. local oldpart = nil
  6. local currentpart = nil
  7. local currentcf = nil
  8. local vel = Vector3.new(0,0,0)
  9. local lastpos = Vector3.new(0,0,0)
  10. local remote = player:WaitForChild("lud")
  11.  
  12. function subtractcf(a, b)
  13. local x, y, z, m11, m12, m13, m21, m22, m23, m31, m32, m33 = a:components()
  14. return CFrame.new(x - b.x, y - b.y, z - b.z, m11, m12, m13, m21, m22, m23, m31, m32, m33);
  15. end
  16.  
  17. local function multiplyCFrame(a, b)
  18. local ax, ay, az, a11, a12, a13, a21, a22, a23, a31, a32, a33 = a:components()
  19. local bx, by, bz, b11, b12, b13, b21, b22, b23, b31, b32, b33 = b:components()
  20. local x = ax*bx
  21. local y = ay*by
  22. local z = az*bz
  23. local m11 = a11*b11
  24. local m12 = a12*b12
  25. local m13 = a13*b13
  26. local m21 = a21*b21
  27. local m22 = a22*b22
  28. local m23 = a23*b23
  29. local m31 = a31*b31
  30. local m32 = a32*b32
  31. local m33 = a33*b33
  32. return CFrame.new(x, y, z, m11, m12, m13, m21, m22, m23, m31, m32, m33)
  33. end
  34.  
  35. us.InputBegan:Connect(function(inp)
  36. if inp.UserInputType == Enum.UserInputType.MouseButton1 then
  37. local target = mouse.Target
  38. lastpos = target.Position
  39. currentcf = cam.CFrame:toObjectSpace(target.CFrame)
  40. currentpart = target
  41. remote:FireServer("anchor",currentpart)
  42. end
  43. end)
  44.  
  45. us.InputEnded:Connect(function(inp)
  46. if inp.UserInputType == Enum.UserInputType.MouseButton1 then
  47. --currentpart.Velocity = Vector3.new(vel.X*20,vel.Y*20,vel.Z*20)
  48. remote:FireServer("unanchor",currentpart,Vector3.new(vel.X*20,vel.Y*20,vel.Z*20))
  49. vel = Vector3.new(0,0,0)
  50. currentpart = nil
  51. currentcf = nil
  52. if inp.UserInputType == Enum.UserInputType.Keyboard then
  53. if inp.KeyCode == Enum.KeyCode.E then
  54. remote:FireServer("spawnpart")
  55. end
  56. end
  57. end
  58. end)
  59.  
  60. --
  61.  
  62. game:GetService("RunService").RenderStepped:Connect(function()
  63. if currentpart ~= nil and currentcf ~= nil then
  64. currentpart.CFrame = cam.CFrame * currentcf
  65. remote:FireServer("update",currentpart,currentpart.CFrame)
  66. vel = Vector3.new(currentpart.Position.X-lastpos.X,currentpart.Position.Y-lastpos.Y,currentpart.Position.Z-lastpos.Z)
  67. lastpos = currentpart.Position
  68. end
  69. local targ = mouse.Target
  70. if targ ~= nil and targ.Anchored == false then
  71. if targ ~= oldpart and targ.Size.X <= 15 and targ.Size.Y <= 15 and targ.Size.Z <= 15 then
  72. if oldpart ~= nil then
  73. oldpart.Selec:Destroy()
  74. end
  75. local selec = Instance.new("SelectionBox",targ)
  76. selec.Name = "Selec"
  77. selec.Adornee = targ
  78. selec.Color3 = Color3.new(0,0,0)
  79. selec.LineThickness = 0.025
  80. oldpart = targ
  81. elseif targ ~= oldpart and targ.Size.X > 15 and targ.Size.Y > 15 and targ.Size.Z > 15 then
  82. if oldpart ~= nil then
  83. oldpart.Selec:Destroy()
  84. oldpart = nil
  85. end
  86. end
  87. else
  88. if oldpart ~= nil then
  89. oldpart.Selec:Destroy()
  90. oldpart = nil
  91. end
  92. end
  93. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement