Advertisement
UniverseisCool

telekinesis

Dec 21st, 2017
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.22 KB | None | 0 0
  1. local next=next
  2.  
  3. local sin=math.sin
  4.  
  5. local cos=math.cos
  6.  
  7. local max=math.max
  8.  
  9. local min=math.min
  10.  
  11. local tau=2*math.pi
  12.  
  13. local atan2=math.atan2
  14.  
  15. local random=math.random
  16.  
  17. local gp=game:service'Players'
  18.  
  19. local M=gp.LocalPlayer
  20.  
  21. script.Parent=nil
  22.  
  23.  
  24. local function test(f)
  25.  
  26. local a,b=coroutine.resume(coroutine.create(f))
  27.  
  28. if not a then
  29.  
  30. local h=Instance.new("Hint",workspace)
  31.  
  32. h.Name="Error"
  33.  
  34. h.Text=b
  35.  
  36. wait(12)
  37.  
  38. h:Destroy()
  39.  
  40. end
  41.  
  42. return a
  43.  
  44. end
  45.  
  46.  
  47. local touchable={"Part","WedgePart","SpawnLocation","TrussPart","VehicleSeat","Seat","FlagStand","Platform","SkateboardPlatform","ParallelRampPart","PrismPart","PyramidPart","RightAngleRampPart","BasePart"}
  48.  
  49. local index={}
  50.  
  51. local function add(p)
  52.  
  53. 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
  54.  
  55. for i=1,#touchable do
  56.  
  57. if p.ClassName==touchable[i] then
  58.  
  59. index[p]=p:GetMass()
  60.  
  61. break
  62.  
  63. end
  64.  
  65. end
  66.  
  67. end
  68.  
  69. end
  70.  
  71. local function del(p)
  72.  
  73. if index[p] then
  74.  
  75. index[p]=nil
  76.  
  77. end
  78.  
  79. end
  80.  
  81. local function find(p)
  82.  
  83. add(p)
  84.  
  85. local pgc
  86.  
  87. test(function() pgc=p:getChildren() end)
  88.  
  89. if pgc then
  90.  
  91. for _,c in next,pgc do
  92.  
  93. find(c)
  94.  
  95. end
  96.  
  97. end
  98.  
  99. end
  100.  
  101. workspace.DescendantAdded:connect(add)
  102.  
  103. workspace.DescendantRemoving:connect(del)
  104.  
  105. find(workspace)
  106.  
  107.  
  108. local function getmass(obj)
  109.  
  110. local total=0
  111.  
  112. for i=1,#touchable do
  113.  
  114. if obj.ClassName==touchable[i] then
  115.  
  116. total=index[obj] or obj:GetMass()
  117.  
  118. break
  119.  
  120. end
  121.  
  122. end
  123.  
  124. for _,ch in next,obj:GetChildren() do
  125.  
  126. total=total+getmass(ch)
  127.  
  128. end
  129.  
  130. return total
  131.  
  132. end
  133.  
  134. local maxdis=29
  135.  
  136. local grav=280.89
  137.  
  138. local A,B="http://www.roblox.com/asset?id=","http://www.roblox.com/asset?id="
  139.  
  140. local tool=Instance.new'HopperBin'
  141.  
  142. tool.Name="Telekenesis"
  143.  
  144. tool.TextureId="http://www.roblox.com/asset?id="
  145.  
  146. local ev1,ev2,ev3,ev4,ev5
  147.  
  148. local mindex
  149.  
  150. local go=function()
  151.  
  152. if M.Parent then
  153.  
  154. if mindex then
  155.  
  156. for part,i in next,mindex do
  157.  
  158. i.body:Destroy()
  159.  
  160. i.ang:Destroy()
  161.  
  162. end
  163.  
  164. mindex=nil
  165.  
  166. end
  167.  
  168. if ev1 and ev2 and ev3 and ev4 and ev5 then
  169.  
  170. ev1:disconnect()
  171.  
  172. ev2:disconnect()
  173.  
  174. ev3:disconnect()
  175.  
  176. ev4:disconnect()
  177.  
  178. ev5:disconnect()
  179.  
  180. end
  181.  
  182. local newtool=tool:Clone()
  183.  
  184. newtool.Parent=M.Backpack
  185.  
  186. ev1=newtool.Selected:connect(function(m)
  187.  
  188. newtool.Parent=nil
  189.  
  190. m.Icon=A
  191.  
  192. local multi=false
  193.  
  194. local grab=false
  195.  
  196. local props
  197.  
  198. local v,d,pos
  199.  
  200. local lpos
  201.  
  202. local body,ang=Instance.new'BodyPosition',Instance.new'BodyAngularVelocity'
  203.  
  204. local mdown=false
  205.  
  206. local function shoot(part,target)
  207.  
  208. if multi and mindex then
  209.  
  210. --aim trajectory :D
  211.  
  212. part.Velocity=(target-part.Position).unit*grav
  213.  
  214. end
  215.  
  216. end
  217.  
  218. local function fire(tgt)
  219.  
  220. local nump=0
  221.  
  222. local cp
  223.  
  224. local d=math.huge
  225.  
  226. for part,i in next,mindex do
  227.  
  228. nump=nump+1
  229.  
  230. local thisd=(part.Position-tgt).magnitude
  231.  
  232. if thisd<d then
  233.  
  234. d=thisd
  235.  
  236. cp=part
  237.  
  238. end
  239.  
  240. end
  241.  
  242. if cp and mindex[cp] then
  243.  
  244. mindex[cp].ang:Destroy()
  245.  
  246. mindex[cp].body:Destroy()
  247.  
  248. mindex[cp]=nil
  249.  
  250. shoot(cp,tgt)
  251.  
  252. if nump==1 then
  253.  
  254. multi=false
  255.  
  256. end
  257.  
  258. else
  259.  
  260. multi=false
  261.  
  262. end
  263.  
  264. end
  265.  
  266. ev2=m.Button1Down:connect(function()
  267.  
  268. test(function()
  269.  
  270. mdown=true
  271.  
  272. if not (grab or multi) then
  273.  
  274. v=m.Target
  275.  
  276. if v and (v.ClassName=="Part" and v.Name~="Base") then
  277. sel = Instance.new("SelectionBox", v) sel.Adornee = v sel.Transparency = 2222222222222222222 sel.Color = BrickColor.new("red")
  278. light = Instance.new("PointLight", v) light.Brightness = 90222222
  279.  
  280. local mass=v:GetMass()
  281.  
  282. for _,p in next,workspace:GetChildren() do
  283.  
  284. if p:findFirstChild'Humanoid' and p:IsAncestorOf(v) then
  285.  
  286. mass=getmass(p)
  287.  
  288. break
  289.  
  290. end
  291.  
  292. end
  293.  
  294. local mg=mass*grav
  295.  
  296. body.maxForce=Vector3.new(2*mg,3*mg,2*mg)
  297.  
  298. m.Icon=B
  299.  
  300. d=m.UnitRay.Direction:Dot(v.Position-m.Origin.p)
  301.  
  302. pos=m.Origin.p+m.UnitRay.Direction*d
  303.  
  304. props={Anchored=v.Anchored,CanCollide=v.CanCollide}
  305.  
  306. v.CanCollide=true
  307.  
  308. v.Anchored=false
  309.  
  310. ang.Parent,body.Parent=v,v
  311.  
  312. grab=true
  313.  
  314. end
  315.  
  316. local vel=Vector3.new(0,0,0)
  317.  
  318. local vlev=random()*math.pi
  319.  
  320. local rpos=Vector3.new(random()*2-1,cos(vlev),random()*2-1)
  321.  
  322. while grab do
  323.  
  324. pos=m.Origin.p+m.UnitRay.Direction*d
  325.  
  326. ang.angularvelocity=vel
  327.  
  328. body.position=pos+rpos
  329.  
  330. 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)))
  331.  
  332. 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)))
  333.  
  334. vlev=(vlev+0.05)%tau
  335.  
  336. wait()
  337.  
  338. end
  339.  
  340. elseif multi then
  341.  
  342. --shoot at target
  343.  
  344. --test(function()
  345.  
  346. if m.hit then
  347.  
  348. fire(m.hit.p)
  349.  
  350. else
  351.  
  352. fire(m.Origin.p+m.UnitRay.Direction)
  353.  
  354. end
  355.  
  356. for i=1,15 do
  357.  
  358. if not mdown then
  359.  
  360. break
  361.  
  362. else
  363.  
  364. wait()
  365.  
  366. end
  367.  
  368. end
  369.  
  370. while mdown and multi do
  371.  
  372. if m.hit then
  373.  
  374. fire(m.hit.p)
  375.  
  376. else
  377.  
  378. fire(m.Origin.p+m.UnitRay.Direction)
  379.  
  380. end
  381.  
  382. wait()
  383.  
  384. end
  385.  
  386. --end)
  387.  
  388. end
  389.  
  390. end)
  391.  
  392. end)
  393.  
  394. ev3=m.Move:connect(function()
  395.  
  396. if grab then
  397.  
  398. pos=m.Origin.p+m.UnitRay.Direction*d
  399.  
  400. end
  401.  
  402. end)
  403.  
  404. local stopgrab=function()
  405.  
  406. if grab then
  407.  
  408. grab=false
  409.  
  410. m.Icon=A
  411.  
  412. wait()
  413.  
  414. --[[for i,p in next,props do
  415.  
  416. v[i]=p
  417.  
  418. end]]
  419.  
  420. ang.Parent,body.Parent=nil,nil
  421.  
  422. props,v,d,pos=nil,nil,nil,nil
  423.  
  424. end
  425.  
  426. end
  427.  
  428. ev4=m.Button1Up:connect(function()
  429. pcall(function()
  430. v.PointLight:Remove()
  431. v.SelectionBox:Remove()
  432. end)
  433. mdown=false
  434.  
  435. stopgrab()
  436.  
  437. end)
  438.  
  439. ev5=m.KeyDown:connect(function(k)
  440.  
  441. --test(function()
  442.  
  443. if grab then
  444.  
  445. if k=="f"then
  446.  
  447. local vic=v
  448.  
  449. stopgrab()
  450.  
  451. vic.Velocity=m.UnitRay.Direction*grav
  452.  
  453. elseif k=="x" then
  454.  
  455. v:BreakJoints()
  456.  
  457. end
  458.  
  459. elseif multi then
  460.  
  461. if k=="f" then
  462.  
  463. --explod'em
  464.  
  465. for part,i in next,mindex do
  466.  
  467. i.body:Destroy()
  468.  
  469. i.ang:Destroy()
  470.  
  471. part.Velocity=(part.Position-lpos).unit*(2/3)*grav
  472.  
  473. end
  474.  
  475. mindex=nil
  476.  
  477. multi=false
  478.  
  479. elseif k=="c" then
  480.  
  481. --drop 'em
  482.  
  483. for part,i in next,mindex do
  484.  
  485. i.body:Destroy()
  486.  
  487. i.ang:Destroy()
  488.  
  489. end
  490.  
  491. mindex=nil
  492.  
  493. multi=false
  494.  
  495. elseif k=="z" then
  496.  
  497. --speed up
  498.  
  499. for _,i in next,mindex do
  500.  
  501. i.const=i.const+0.02
  502.  
  503. end
  504.  
  505. end
  506.  
  507. else
  508.  
  509. if k=="c" and M.Character and M.Character:findFirstChild'Torso' then
  510.  
  511. local t=M.Character.Torso
  512.  
  513. mindex={}
  514.  
  515. local num=0
  516.  
  517. for part,weight in next,index do
  518.  
  519. local dis=(part.Position-t.Position).magnitude
  520.  
  521. if M.Character and not part:IsDescendantOf(M.Character) and weight<=1000 and dis<=maxdis then
  522.  
  523. mindex[part]=dis
  524.  
  525. num=num+1
  526.  
  527. end
  528.  
  529. end
  530.  
  531. local chance=num^-0.01
  532.  
  533. for part,dis in next,mindex do
  534.  
  535. if random()<=chance*(1-(dis/maxdis)^3) then
  536.  
  537. local mg=index[part]*grav
  538.  
  539. local vlev=random()*math.pi
  540.  
  541. local bod,an=body:Clone(),ang:Clone()
  542.  
  543. bod.Parent,an.Parent=part,part
  544.  
  545. bod.maxForce=Vector3.new(mg,2*mg,mg)
  546.  
  547. bod.position=part.Position
  548.  
  549. an.angularvelocity=Vector3.new(0,0,0)
  550.  
  551. part:BreakJoints()
  552.  
  553. local diff=part.Position-t.Position
  554.  
  555. local step1=Vector3.new(diff.x,0,diff.z).unit
  556.  
  557. local step2=step1*(10+random()*8)
  558.  
  559. mindex[part]={
  560.  
  561. angle=math.pi-atan2(step2.x,-step2.z),
  562.  
  563. mag=step2.magnitude,
  564.  
  565. ypos=random()*8,
  566.  
  567. vlev=vlev,
  568.  
  569. vel=Vector3.new(0,0,0),
  570.  
  571. rpos=Vector3.new(random()*2-1,cos(vlev),random()*2-1),
  572.  
  573. body=bod,
  574.  
  575. ang=an,
  576.  
  577. const=random()*0.01+0.01,
  578.  
  579. Anchored=part.Anchored,
  580.  
  581. CanCollide=part.CanCollide
  582.  
  583. }
  584.  
  585. part.CanCollide=true
  586.  
  587. part.Anchored=false
  588.  
  589. else
  590.  
  591. mindex[part]=nil
  592.  
  593. end
  594.  
  595. end
  596.  
  597. multi=true
  598.  
  599. lpos=t.Position
  600.  
  601. while multi and t and t.Parent and t.Parent.Parent do
  602.  
  603. for _,i in next,mindex do
  604.  
  605. i.ang.angularvelocity=i.vel
  606.  
  607. i.body.position=t.Position+Vector3.new(sin(i.angle)*i.mag,i.ypos,cos(i.angle)*i.mag)+i.rpos
  608.  
  609. 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)))
  610.  
  611. 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)))
  612.  
  613. if mdown then
  614.  
  615. i.angle=(i.angle+i.const*4)%tau
  616.  
  617. else
  618.  
  619. i.angle=(i.angle+i.const)%tau
  620.  
  621. end
  622.  
  623. i.vlev=(i.vlev+0.05)%tau
  624.  
  625. end
  626.  
  627. lpos=t.Position
  628.  
  629. wait()
  630.  
  631. end
  632.  
  633. end
  634.  
  635. end
  636.  
  637. --end)
  638.  
  639. end)
  640.  
  641. end)
  642.  
  643. end
  644.  
  645. end
  646.  
  647.  
  648. go()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement