Laith8888

Roblox Telekinesis script

Feb 8th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.04 KB | None | 0 0
  1. --Telekinesis by flipflop8421
  2. local next=next
  3. local sin=math.sin
  4. local cos=math.cos
  5. local max=math.max
  6. local min=math.min
  7. local tau=2*math.pi
  8. local atan2=math.atan2
  9. local random=math.random
  10. local gp=game:service'Players'
  11. local M=gp.LocalPlayer
  12. script.Parent=nil
  13. local function test(f)
  14. local a,b=coroutine.resume(coroutine.create(f))
  15. if not a then
  16. local h=Instance.new("Hint",workspace)
  17. h.Name="Error"
  18. h.Text=b
  19. wait(12)
  20. h:Destroy()
  21. end
  22. return a
  23. end
  24. local touchable={"Part","WedgePart","SpawnLocation","TrussPart","VehicleSeat","Seat","FlagStand","Platform","SkateboardPlatform","ParallelRampPart","PrismPart","PyramidPart","RightAngleRampPart","BasePart"}
  25. local index={}
  26. local function add(p)
  27. if test(function() return p.ClassName end) and not index[p] and not (p.Name=="Base" and p.Parent==workspace and p.ClassName=="Part") then
  28. for i=1,#touchable do
  29. if p.ClassName==touchable[i] then
  30. index[p]=p:GetMass()
  31. break
  32. end
  33. end
  34. end
  35. end
  36. local function del(p)
  37. if index[p] then
  38. index[p]=nil
  39. end
  40. end
  41. local function find(p)
  42. add(p)
  43. local pgc
  44. test(function() pgc=p:getChildren() end)
  45. if pgc then
  46. for _,c in next,pgc do
  47. find(c)
  48. end
  49. end
  50. end
  51. workspace.DescendantAdded:connect(add)
  52. workspace.DescendantRemoving:connect(del)
  53. find(workspace)
  54. local function getmass(obj)
  55. local total=0
  56. for i=1,#touchable do
  57. if obj.ClassName==touchable[i] then
  58. total=index[obj] or obj:GetMass()
  59. break
  60. end
  61. end
  62. for _,ch in next,obj:GetChildren() do
  63. total=total+getmass(ch)
  64. end
  65. return total
  66. end
  67. local maxdis=20
  68. local grav=196.2
  69. local A,B="http://www.roblox.com/asset?id=88251961","http://www.roblox.com/asset?id=88252842"
  70. local tool=Instance.new'HopperBin'
  71. tool.Name="Telekenesis"
  72. tool.TextureId="http://www.roblox.com/asset?id=88241634"
  73. local ev1,ev2,ev3,ev4,ev5
  74. local mindex
  75. local go=function()
  76. if M.Parent then
  77. if mindex then
  78. for part,i in next,mindex do
  79. i.body:Destroy()
  80. i.ang:Destroy()
  81. end
  82. mindex=nil
  83. end
  84. if ev1 and ev2 and ev3 and ev4 and ev5 then
  85. ev1:disconnect()
  86. ev2:disconnect()
  87. ev3:disconnect()
  88. ev4:disconnect()
  89. ev5:disconnect()
  90. end
  91. local newtool=tool:Clone()
  92. newtool.Parent=M.Backpack
  93. ev1=newtool.Selected:connect(function(m)
  94. newtool.Parent=nil
  95. m.Icon=A
  96. local multi=false
  97. local grab=false
  98. local props
  99. local v,d,pos
  100. local lpos
  101. local body,ang=Instance.new'BodyPosition',Instance.new'BodyAngularVelocity'
  102. local mdown=false
  103. local function shoot(part,target)
  104. if multi and mindex then
  105. --aim trajectory :D
  106. part.Velocity=(target-part.Position).unit*grav
  107. end
  108. end
  109. local function fire(tgt)
  110. local nump=0
  111. local cp
  112. local d=math.huge
  113. for part,i in next,mindex do
  114. nump=nump+1
  115. local thisd=(part.Position-tgt).magnitude
  116. if thisd<d then
  117. d=thisd
  118. cp=part
  119. end
  120. end
  121. if cp and mindex[cp] then
  122. mindex[cp].ang:Destroy()
  123. mindex[cp].body:Destroy()
  124. mindex[cp]=nil
  125. shoot(cp,tgt)
  126. if nump==1 then
  127. multi=false
  128. end
  129. else
  130. multi=false
  131. end
  132. end
  133. ev2=m.Button1Down:connect(function()
  134. test(function()
  135. mdown=true
  136. if not (grab or multi) then
  137. v=m.Target
  138. if v and (v.ClassName=="Part" and v.Name~="Base") then
  139. local mass=v:GetMass()
  140. for _,p in next,workspace:GetChildren() do
  141. if p:findFirstChild'Humanoid' and p:IsAncestorOf(v) then
  142. mass=getmass(p)
  143. break
  144. end
  145. end
  146. local mg=mass*grav
  147. body.maxForce=Vector3.new(2*mg,3*mg,2*mg)
  148. m.Icon=B
  149. d=m.UnitRay.Direction:Dot(v.Position-m.Origin.p)
  150. pos=m.Origin.p+m.UnitRay.Direction*d
  151. props={Anchored=v.Anchored,CanCollide=v.CanCollide}
  152. v.CanCollide=true
  153. v.Anchored=false
  154. ang.Parent,body.Parent=v,v
  155. grab=true
  156. end
  157. local vel=Vector3.new(0,0,0)
  158. local vlev=random()*math.pi
  159. local rpos=Vector3.new(random()*2-1,cos(vlev),random()*2-1)
  160. while grab do
  161. pos=m.Origin.p+m.UnitRay.Direction*d
  162. ang.angularvelocity=vel
  163. body.position=pos+rpos
  164. rpos=Vector3.new(max(-1,min(rpos.x+random()*0.02-0.01,1)),cos(vlev),max(-1,min(rpos.z+random()*0.02-0.01,1)))
  165. vel=Vector3.new(max(-1,min(vel.x+random()*0.2-0.1,1)),max(-1,min(vel.y+random()*0.2-0.1,1)),max(-1,min(vel.z+random()*0.2-0.1,1)))
  166. vlev=(vlev+0.05)%tau
  167. wait()
  168. end
  169. elseif multi then
  170. --shoot at target
  171. --test(function()
  172. if m.hit then
  173. fire(m.hit.p)
  174. else
  175. fire(m.Origin.p+m.UnitRay.Direction)
  176. end
  177. for i=1,15 do
  178. if not mdown then
  179. break
  180. else
  181. wait()
  182. end
  183. end
  184. while mdown and multi do
  185. if m.hit then
  186. fire(m.hit.p)
  187. else
  188. fire(m.Origin.p+m.UnitRay.Direction)
  189. end
  190. wait()
  191. end
  192. --end)
  193. end
  194. end)
  195. end)
  196. ev3=m.Move:connect(function()
  197. if grab then
  198. pos=m.Origin.p+m.UnitRay.Direction*d
  199. end
  200. end)
  201. local stopgrab=function()
  202. if grab then
  203. grab=false
  204. m.Icon=A
  205. wait()
  206. --[[for i,p in next,props do
  207. v[i]=p
  208. end]]
  209. ang.Parent,body.Parent=nil,nil
  210. props,v,d,pos=nil,nil,nil,nil
  211. end
  212. end
  213. ev4=m.Button1Up:connect(function()
  214. mdown=false
  215. stopgrab()
  216. end)
  217. ev5=m.KeyDown:connect(function(k)
  218. --test(function()
  219. if grab then
  220. if k=="f"then
  221. local vic=v
  222. stopgrab()
  223. vic.Velocity=m.UnitRay.Direction*grav
  224. elseif k=="x" then
  225. v:BreakJoints()
  226. end
  227. elseif multi then
  228. if k=="f" then
  229. --explod'em
  230. for part,i in next,mindex do
  231. i.body:Destroy()
  232. i.ang:Destroy()
  233. part.Velocity=(part.Position-lpos).unit*(2/3)*grav
  234. end
  235. mindex=nil
  236. multi=false
  237. elseif k=="c" then
  238. --drop 'em
  239. for part,i in next,mindex do
  240. i.body:Destroy()
  241. i.ang:Destroy()
  242. end
  243. mindex=nil
  244. multi=false
  245. elseif k=="z" then
  246. --speed up
  247. for _,i in next,mindex do
  248. i.const=i.const+0.02
  249. end
  250. end
  251. else
  252. if k=="c" and M.Character and M.Character:findFirstChild'Torso' then
  253. local t=M.Character.Torso
  254. mindex={}
  255. local num=0
  256. for part,weight in next,index do
  257. local dis=(part.Position-t.Position).magnitude
  258. if M.Character and not part:IsDescendantOf(M.Character) and weight<=1000 and dis<=maxdis then
  259. mindex[part]=dis
  260. num=num+1
  261. end
  262. end
  263. local chance=num^-0.01
  264. for part,dis in next,mindex do
  265. if random()<=chance*(1-(dis/maxdis)^3) then
  266. local mg=index[part]*grav
  267. local vlev=random()*math.pi
  268. local bod,an=body:Clone(),ang:Clone()
  269. bod.Parent,an.Parent=part,part
  270. bod.maxForce=Vector3.new(mg,2*mg,mg)
  271. bod.position=part.Position
  272. an.angularvelocity=Vector3.new(0,0,0)
  273. part:BreakJoints()
  274. local diff=part.Position-t.Position
  275. local step1=Vector3.new(diff.x,0,diff.z).unit
  276. local step2=step1*(10+random()*8)
  277. mindex[part]={
  278. angle=math.pi-atan2(step2.x,-step2.z),
  279. mag=step2.magnitude,
  280. ypos=random()*8,
  281. vlev=vlev,
  282. vel=Vector3.new(0,0,0),
  283. rpos=Vector3.new(random()*2-1,cos(vlev),random()*2-1),
  284. body=bod,
  285. ang=an,
  286. const=random()*0.01+0.01,
  287. Anchored=part.Anchored,
  288. CanCollide=part.CanCollide
  289. }
  290. part.CanCollide=true
  291. part.Anchored=false
  292. else
  293. mindex[part]=nil
  294. end
  295. end
  296. multi=true
  297. lpos=t.Position
  298. while multi and t and t.Parent and t.Parent.Parent do
  299. for _,i in next,mindex do
  300. i.ang.angularvelocity=i.vel
  301. i.body.position=t.Position+Vector3.new(sin(i.angle)*i.mag,i.ypos,cos(i.angle)*i.mag)+i.rpos
  302. i.rpos=Vector3.new(max(-1,min(i.rpos.x+random()*0.02-0.01,1)),cos(i.vlev),max(-1,min(i.rpos.z+random()*0.02-0.01,1)))
  303. i.vel=Vector3.new(max(-1,min(i.vel.x+random()*0.2-0.1,1)),max(-1,min(i.vel.y+random()*0.2-0.1,1)),max(-1,min(i.vel.z+random()*0.2-0.1,1)))
  304. if mdown then
  305. i.angle=(i.angle+i.const*4)%tau
  306. else
  307. i.angle=(i.angle+i.const)%tau
  308. end
  309. i.vlev=(i.vlev+0.05)%tau
  310. end
  311. lpos=t.Position
  312. wait()
  313. end
  314. end
  315. end
  316. --end)
  317. end)
  318. end)
  319. end
  320. end
  321. M.CharacterAdded:connect(go)
  322. go()
Add Comment
Please, Sign In to add comment