Advertisement
Guest User

Untitled

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