Advertisement
BobMe

Untitled

Feb 10th, 2022
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. local gravity = 0.1 -- earth gravity
  2. local friction = 1
  3. script.Name = "ORBYORB"..tostring(math.random(34,32764))
  4. local function AccurateWait(seconds)
  5. local RunService = game:GetService("RunService")
  6. if not seconds then
  7. seconds = 0
  8. end
  9. local last = tick()
  10. local secondsPassed = 0
  11. local connection = RunService.Heartbeat:Connect(function(dt)
  12. secondsPassed = secondsPassed + dt
  13. end)
  14. repeat
  15. RunService.Heartbeat:Wait()
  16. until secondsPassed >= seconds
  17. connection:Disconnect()
  18. end
  19. local function reverse_table(tab)
  20. local function deepCopy(original)
  21. local copy = {}
  22. for k, v in pairs(original) do
  23. if type(v) == "table" then
  24. v = deepCopy(v)
  25. end
  26. copy[k] = v
  27. end
  28. return copy
  29. end
  30. local t = deepCopy(tab)
  31. for i = 1, math.floor(#t/2) do
  32. local j = #t - i + 1
  33. t[i], t[j] = t[j], t[i]
  34. end
  35. return t
  36. end
  37. local function findParent(part)
  38. local tab = {}
  39. local current = part
  40. while current ~= game do
  41. table.insert(tab,tostring(current))
  42. current = current.Parent
  43. end
  44. tab = reverse_table(tab)
  45. local str = "game."
  46. for i,v in pairs(tab) do
  47. str = str..v.."."
  48. end
  49. return string.sub(str,1,#str-1)
  50. end
  51. local center = nil
  52.  
  53. local function addObject(pos,centerofgravityobj,usecenter)
  54. coroutine.resume(coroutine.create(function()
  55. local remote = Instance.new("RemoteEvent",owner.Character)
  56. local part = Instance.new("Part",script)
  57. part.Name = "orb"..tostring(math.random(1,999999))
  58. part.CFrame = pos
  59. part.Anchored = true
  60. local num = math.random(5,50)/10
  61. part.Size = Vector3.new(num,num,num)
  62. part.Shape = Enum.PartType.Ball
  63. part.Material = Enum.Material.Neon
  64. part.Color = Color3.new(math.random(),math.random(),math.random())
  65. local atch1 = Instance.new("Attachment",part)
  66. atch1.Position = Vector3.new(0,part.Size.Y/2,0)
  67. local atch2 = Instance.new("Attachment",part)
  68. atch2.Position = Vector3.new(0,part.Size.Y/2*-1,0)
  69. local trail = Instance.new("Trail",part)
  70. trail.Attachment0 = atch1
  71. trail.Attachment1 = atch2
  72. trail.Color = ColorSequence.new(part.Color,part.Color)
  73. trail.Lifetime = 0.3
  74. trail.WidthScale = NumberSequence.new(3,0)
  75. trail.Texture = "http://www.roblox.com/asset/?id=5699911427"
  76. trail.LightEmission = 1
  77. trail.FaceCamera = true
  78. if usecenter then
  79. centerofgravityobj = center
  80. end
  81. wait()
  82. NLS([[
  83. local function AccurateWait(seconds)
  84. local RunService = game:GetService("RunService")
  85. if not seconds then
  86. seconds = 0
  87. end
  88. local last = tick()
  89. local secondsPassed = 0
  90. local connection = RunService.Heartbeat:Connect(function(dt)
  91. secondsPassed = secondsPassed + dt
  92. end)
  93. repeat
  94. RunService.Heartbeat:Wait()
  95. until secondsPassed >= seconds
  96. connection:Disconnect()
  97. end
  98. local p = ]]..findParent(part)..[[
  99. local part = p:Clone()
  100. --part.CanCollide = false
  101. part.Parent = p.Parent
  102. p:Destroy()
  103. local velocity = Vector2.new(0,0)
  104. local gravity = ]]..tostring(gravity)..[[
  105. local friction = ]]..tostring(friction)..[[
  106. while true do
  107. local op = ]]..findParent(centerofgravityobj)..[[.Position
  108. local pp = part.Position
  109. local mag = (op-pp).Magnitude
  110. local mass = ((mag*1)^-0.5)/0.25
  111. local x = pp.X + (0-op.X)
  112. local z = pp.Z + (0-op.Z)
  113. local degree = math.deg(math.asin(x/mag))
  114. local xdirection = degree/90
  115. local zdirection = 1-math.abs(xdirection)
  116. if z < 0 then
  117. zdirection = zdirection * -1
  118. end
  119. velocity = Vector2.new((velocity.X*friction)+(xdirection*gravity*mass),(velocity.Y*friction)+(zdirection*gravity*mass))
  120. part.Position = part.Position + Vector3.new(velocity.X*-1,0,velocity.Y*-1)
  121. script.Parent:FireServer(part.Position)
  122. AccurateWait()
  123. end]],remote)
  124. remote.OnServerEvent:Connect(function(plr,poss)
  125. if plr == owner then
  126. part.Position = poss
  127. end
  128. end)
  129. end))
  130. end
  131.  
  132. --
  133. addObject(owner.Character.Head.CFrame * CFrame.new(0,0,0),owner.Character.HumanoidRootPart)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement