BobMe

YeetL

Aug 22nd, 2020
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 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 strength = 1
  9. local vel = Vector3.new(0,0,0)
  10. local lastpos = Vector3.new(0,0,0)
  11. local remote = player:WaitForChild("Yet")
  12.  
  13. player.Chatted:Connect(function(msg)
  14. if string.sub(string.lower(msg),1,10) == ";strength " then
  15. local num = tonumber(string.sub(msg,11))
  16. if num ~= nil then
  17. strength = num
  18. end
  19. end
  20. end)
  21.  
  22. function subtractcf(a, b)
  23. local x, y, z, m11, m12, m13, m21, m22, m23, m31, m32, m33 = a:components()
  24. return CFrame.new(x - b.x, y - b.y, z - b.z, m11, m12, m13, m21, m22, m23, m31, m32, m33);
  25. end
  26.  
  27. local function multiplyCFrame(a, b)
  28. local ax, ay, az, a11, a12, a13, a21, a22, a23, a31, a32, a33 = a:components()
  29. local bx, by, bz, b11, b12, b13, b21, b22, b23, b31, b32, b33 = b:components()
  30. local x = ax*bx
  31. local y = ay*by
  32. local z = az*bz
  33. local m11 = a11*b11
  34. local m12 = a12*b12
  35. local m13 = a13*b13
  36. local m21 = a21*b21
  37. local m22 = a22*b22
  38. local m23 = a23*b23
  39. local m31 = a31*b31
  40. local m32 = a32*b32
  41. local m33 = a33*b33
  42. return CFrame.new(x, y, z, m11, m12, m13, m21, m22, m23, m31, m32, m33)
  43. end
  44.  
  45. function valid(part)
  46. if part.Anchored == false then
  47. return true
  48. else
  49. return false
  50. end
  51. end
  52.  
  53. us.InputBegan:Connect(function(inp)
  54. if inp.UserInputType == Enum.UserInputType.MouseButton1 then
  55. local target = mouse.Target
  56. if valid(target) then
  57. lastpos = target.Position
  58. currentcf = cam.CFrame:toObjectSpace(target.CFrame)
  59. currentpart = target
  60. remote:FireServer("anchor",currentpart)
  61. end
  62. end
  63. end)
  64.  
  65. us.InputEnded:Connect(function(inp)
  66. if inp.UserInputType == Enum.UserInputType.MouseButton1 then
  67. --currentpart.Velocity = Vector3.new(vel.X*20,vel.Y*20,vel.Z*20)
  68. remote:FireServer("unanchor",currentpart,Vector3.new((vel.X*20)*strength,(vel.Y*20)*strength,(vel.Z*20)*strength))
  69. vel = Vector3.new(0,0,0)
  70. currentpart = nil
  71. currentcf = nil
  72. end
  73. end)
  74.  
  75. mouse.KeyUp:Connect(function(key)
  76. if key:lower() == "e" then
  77. remote:FireServer("spawnpart")
  78. end
  79. end)
  80.  
  81. --
  82.  
  83. game:GetService("RunService").RenderStepped:Connect(function()
  84. if currentpart ~= nil and currentcf ~= nil then
  85. currentpart.CFrame = cam.CFrame * currentcf
  86. remote:FireServer("update",currentpart,currentpart.CFrame)
  87. vel = Vector3.new(currentpart.Position.X-lastpos.X,currentpart.Position.Y-lastpos.Y,currentpart.Position.Z-lastpos.Z)
  88. lastpos = currentpart.Position
  89. end
  90. local targ = mouse.Target
  91. if targ ~= nil and targ.Anchored == false then
  92. if targ ~= oldpart and valid(targ) then
  93. if oldpart ~= nil then
  94. oldpart.Selec:Destroy()
  95. end
  96. local selec = Instance.new("SelectionBox",targ)
  97. selec.Name = "Selec"
  98. selec.Adornee = targ
  99. selec.Color3 = Color3.new(0,0,0)
  100. selec.LineThickness = 0.025
  101. oldpart = targ
  102. elseif targ ~= oldpart and not valid(targ) then
  103. if oldpart ~= nil then
  104. oldpart.Selec:Destroy()
  105. oldpart = nil
  106. end
  107. end
  108. else
  109. if oldpart ~= nil then
  110. oldpart.Selec:Destroy()
  111. oldpart = nil
  112. end
  113. end
  114. end)
Add Comment
Please, Sign In to add comment