lotushomerun

Roblox Automatic Pistol Script

Apr 20th, 2017
4,911
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.03 KB | None | 0 0
  1. print("Glock Script Loaded!")
  2. wait(0.25);
  3.  
  4.  
  5. _clear=function()
  6. local c={char;bag;gui;};
  7. for i=1,#c do
  8. local c=c[i]:children();
  9. for i=1,#c do
  10. if(c[i].Name==name)then
  11. c[i].Parent=nil;
  12. end;
  13. end;
  14. end;
  15. local n=name..user.Name;
  16. local c=workspace:children();
  17. for i=1,#c do
  18. if(c[i].Name==n)then
  19. c[i].Parent=nil;
  20. end;
  21. end;
  22. end;
  23.  
  24. _valid_key=function(object,key)
  25. return object[key],key;
  26. end;
  27.  
  28. _new=function(class)
  29. return function(props)
  30. if(type(list_base_props)=='table')then
  31. for i,v in next,list_base_props do
  32. if(props[i]==nil)then
  33. props[i]=v;
  34. end;
  35. end;
  36. end;
  37.  
  38. local object=class;
  39.  
  40. if(type(class)=='string')then
  41. object=Instance.new(class:sub(1,1):upper()..class:sub(2));
  42. end;
  43.  
  44. local parent=props[1];
  45. props[1]=nil;
  46.  
  47. for i,v in next,props do
  48. local load,res,key=pcall(_valid_key,object,i:sub(1,1):upper()..i:sub(2));
  49. if(not load)then
  50. load,res,key=pcall(_valid_key,object,i);
  51. end;
  52.  
  53. if(key)then
  54. t=type(res);
  55. s=tostring(res);
  56. if(t=='userdata'and s=='Signal '..key)then
  57. if(type(v)=='table')then
  58. for i=1,#v do
  59. res:connect(v[i]);
  60. end;
  61. else
  62. res:connect(v);
  63. end;
  64. else
  65. object[key]=v;
  66. end;
  67. end;
  68. end;
  69.  
  70. if(parent)then
  71. object.Parent=parent;
  72. end;
  73.  
  74. return object;
  75. end;
  76. end;
  77.  
  78. _RGB=function(r,g,b)
  79. return Color3.new(r/255,g/255,b/255);
  80. end;
  81.  
  82. _copy=function(o)
  83. local def=o.archivable;
  84. o.archivable=true;
  85. local c=o:clone();
  86. o.archivable=def;
  87. return c;
  88. end;
  89.  
  90. _hum=function(char)
  91. local hum=char:findFirstChild'Humanoid';
  92. if(not hum or hum.className~='Humanoid')then
  93. local c=char:children();
  94. for i=1,#c do
  95. if(c[i].className=='Humanoid')then
  96. return c[i];
  97. end;
  98. end;
  99. else
  100. return hum;
  101. end;
  102. end;
  103.  
  104. _hum_tag=function(hum)
  105. local c=hum:findFirstChild'creator'or Instance.new('ObjectValue',hum);
  106. c.Name='creator';
  107. c.Value=user;
  108. if(hum.Health==0 and not hum:findFirstChild'killed')then
  109. Instance.new('BoolValue',hum).Name='killed';
  110. bullets.clip=bullets.clip;
  111. end;
  112. end;
  113.  
  114. _hum_dam=function(hum,dam,percent)
  115. hum.Health=hum.Health-(percent and hum.MaxHealth*(dam*0.01)or dam);
  116. if(hum.Health<=hum.MaxHealth*0.1)then
  117. _hum_tag(hum);
  118. end;
  119. end;
  120.  
  121. _ray=function(v0,v1,i)
  122. local mag=(v0-v1).magnitude;
  123. local ray=Ray.new(v0,(v1-v0).unit*(mag>999 and 999 or mag));
  124.  
  125. return(type(i)=='table'and workspace.FindPartOnRayWithIgnoreList or workspace.FindPartOnRay)(workspace,ray,i);
  126. end;
  127.  
  128. _must=function(v0,v1,i)
  129. local hit,pos=_ray(v0,v1,i);
  130. return not hit and mouse.target or hit,pos;
  131. end;
  132.  
  133. _cframe=function(x,y,z,r0,r1,r2)
  134. return CFrame.Angles(
  135. math.rad(r0 or 0),
  136. math.rad(r1 or 0),
  137. math.rad(r2 or 0)
  138. )*CFrame.new(x,y,z);
  139. end;
  140.  
  141. _update=function()
  142. if(bool_active and not screen.Parent)then
  143. screen.Parent=gui;
  144. elseif(not bool_active and screen.Parent)then
  145. screen.Parent=nil;
  146. end;
  147. end;
  148.  
  149. _light=function(v0,v1)
  150. local mag=(v0-v1).magnitude;
  151. local len=math.random(2,7);
  152. len=len>mag/2 and mag/2 or len;
  153.  
  154. --[[ local light=_new'part'{
  155. cFrame=CFrame.new(v0,v1);
  156. size=Vector3.new(1,1,1);
  157. color=_RGB(255,255,0);
  158. anchored=true;
  159. inv;
  160. };]]
  161. _new'blockMesh'{
  162. scale=Vector3.new(0.2,0.2,len);
  163. offset=Vector3.new(0,0,-len/2);
  164. light;
  165. };
  166.  
  167. local bb=_new'billboardGui'{
  168. size=UDim2.new(2,0,2,0);
  169. adornee=light;
  170. light;
  171. };
  172. _new'imageLabel'{
  173. image=url:format(109101526);
  174. backgroundTransparency=1;
  175. size=UDim2.new(1,0,1,0);
  176. bb;
  177. };
  178.  
  179. -- _rem(light,0.15);
  180. end;
  181.  
  182. _rem=function(object,del)
  183. if(del)then
  184. delay(del,function()
  185. if(object.Parent)then
  186. object.Parent=nil;
  187. end;
  188. end);
  189. else
  190. pcall(function()
  191. if(object.Parent)then
  192. object.Parent=nil;
  193. end;
  194. end);
  195. end;
  196. end;
  197.  
  198. _blood=function(pos,count)
  199. for i=1,count do
  200. local p=_new'part'{
  201. rotVelocity=Vector3.new(math.random(),math.random(),math.random())*50;
  202. position=pos+Vector3.new(math.random(),math.random(),math.random());
  203. velocity=Vector3.new(math.random(),math.random(),math.random())*50;
  204. size=Vector3.new(math.random(),math.random(),math.random())/3;
  205. color=_RGB(255,0,0);
  206. transparency=0.5;
  207. canCollide=true;
  208. bottomSurface=0;
  209. topSurface=0;
  210. formFactor=3;
  211. locked=true;
  212. inv;
  213. };
  214. delay(5,function()
  215. p.Parent=nil;
  216. end);
  217. end;
  218. end;
  219.  
  220. _make_hue=function()
  221. h_hue=_new'part'{
  222. size=Vector3.new(0.25,1.8,0.35);
  223. color=_RGB(100,100,100);
  224. formFactor=3;
  225. name='hue';
  226. handle;
  227. };
  228. hh_weld=_new'weld'{
  229. c1=_cframe(0,0.5,0);
  230. part0=handle;
  231. part1=h_hue;
  232. handle;
  233. };
  234. end;
  235.  
  236.  
  237. _shot=function(v0,v1)
  238. if(not time_left)then
  239. time_left=0;
  240. end;
  241. if(time_left>time())then
  242. return nil;
  243. else
  244. time_left=time()+math.random(1,10)/100;
  245. end;
  246.  
  247. if(bullets.current<1)then
  248. local tick_sound=head:findFirstChild'tick_sound'or _new'sound'{
  249. soundId='rbxasset://sounds/SWITCH3.wav';
  250. name='tick_sound';
  251. volume=0.2;
  252. pitch=2;
  253. head;
  254. };
  255. tick_sound:play();
  256. if(bullets.clip>0)then
  257. time_left=time()+2;
  258. h_hue:breakJoints();
  259. h_hue.CanCollide=true;
  260. h_hue.Velocity=(h_hue.CFrame*CFrame.new(0,5,0)).lookVector*10;
  261. _rem(h_hue,10);
  262. delay(1.9,function()
  263. _make_hue();
  264. local got=(bullets.clip>bullets.maximum and
  265. bullets.maximum or
  266. bullets.clip)-bullets.current;
  267.  
  268. bullets.clip=bullets.clip-got;
  269. bullets.current=bullets.current+got;
  270. end);
  271. end;
  272. return nil;
  273. else
  274. bullets.current=bullets.current-1;
  275.  
  276. h_weld.C1=_cframe(0,0.75,0,
  277. -math.random(1000,1100)/10,180,0);
  278. d_weld.C1=_cframe(0,-0.25,0.3);
  279.  
  280. --[[lightstuff.Visible=true;
  281. delay(0.1,function()
  282. lightstuff.Visible=false;
  283. end);]]
  284.  
  285. _rem(_new'part'{
  286. velocity=CFrame.new(drag.Position,(drag.CFrame*CFrame.new(-4,-5,0)).p).lookVector*10;
  287. cFrame=drag.CFrame*CFrame.new(-0.5,0,0);
  288. size=Vector3.new(0.1,0.1,0.4);
  289. color=_RGB(200,200,0);
  290. material='Slate';
  291. canCollide=true;
  292. formFactor=3;
  293. inv;
  294. },5);
  295.  
  296. delay(0.1,function()
  297. d_weld.C1=_cframe(0,-0.25,0);
  298. if(bool_active)then
  299. h_weld.C1=h_weld_cf_active;
  300. end;
  301. end)
  302. end;
  303.  
  304. local hit,pos=_must(v0,v1,char);
  305.  
  306. shot_sound:play();
  307.  
  308.  
  309. _rem(_new'part'{
  310. cFrame=CFrame.new(v0,pos)*CFrame.new(0,0,-(v0-pos).magnitude*0.5);
  311. size=Vector3.new(0.1,0.1,(v0-pos).magnitude);
  312. color=_RGB(255,255,0);
  313. transparency=0.6;
  314. reflectance=0.5;
  315. canCollide=false;
  316. bottomSurface=0;
  317. anchored=true;
  318. formFactor=3;
  319. topSurface=0;
  320. inv;
  321. },.15);
  322. _light(v0,v1);
  323.  
  324. if(not hit)then return nil;end;
  325.  
  326. if(hit.Parent.className=='Hat')then
  327. hit:breakJoints();
  328. hit.CanCollide=true;
  329. hit.Velocity=CFrame.new(v0,pos).lookVector*math.random(30,50);
  330. hit.RotVelocity=Vector3.new(math.random(1,90),math.random(1,90),math.random(1,90));
  331. else
  332. local hum=_hum(hit.Parent);
  333. if(not hum)then
  334. if(hit.Anchored==false and hit.Size.magnitude<4)then
  335. hit:breakJoints();
  336. hit.CanCollide=true;
  337. end;
  338. else
  339. _hum_dam(hum,math.random(15,25));
  340. _blood(pos,math.random(3,6));
  341. hit.RotVelocity=Vector3.new(math.random(1,90),math.random(1,90),math.random(1,90))/6;
  342. if(hit.Name=='Head')then
  343. hum.Health=0;
  344. _blood(pos,math.random(3,6));
  345. --[[delay(0.001,function()
  346. _new(workspace:FindFirstChild'head_shot'or'sound'){
  347. pitch=math.random(70,100)*0.01;
  348. soundId=url:format(1876552);
  349. name='head_shot';
  350. workspace;
  351. }:play();
  352. end);]]
  353. _hum_tag(hum);
  354. --[[_rem(_new'part'{
  355. cFrame=CFrame.new(v0,pos)*CFrame.new(0,0,-(v0-pos).magnitude*0.5);
  356. size=Vector3.new(0.1,0.1,(v0-pos).magnitude);
  357. color=torso.Color;
  358. transparency=0.5;
  359. canCollide=false;
  360. bottomSurface=0;
  361. anchored=true;
  362. formFactor=3;
  363. topSurface=0;
  364. inv;
  365. },30);
  366. hit.Parent=nil;
  367. for b=0,1 do
  368. for a=0,1 do
  369. for i=0,1 do
  370. _rem(_new'part'{
  371. velocity=CFrame.new(v0,pos).lookVector*20;
  372. cFrame=hit.CFrame*CFrame.new(i,-b,a);
  373. size=Vector3.new(0.5,0.5,0.5);
  374. color=_RGB(255,255,255);
  375. bottomSurface=0;
  376. canCollide=true;
  377. transparency=0;
  378. formFactor=3;
  379. topSurface=0;
  380. hum;
  381. },30);
  382. end;
  383. end;
  384. end;]]
  385. end;
  386. end;
  387. end;
  388. end;
  389.  
  390.  
  391.  
  392. _cf_select=function(mouse)
  393. mouse.Icon=url:format(109111387);--108999296
  394. bool_active=true;
  395.  
  396. local arm=char:findFirstChild'Right Arm';
  397. local weld=torso:findFirstChild'Right Shoulder';
  398. if(arm and weld)then
  399. h_weld.Part0=arm;
  400. h_weld.C1=h_weld_cf_active;
  401.  
  402. weld.Part1=nil;
  403. weld.Part0=nil;
  404.  
  405. weld=_new(torso:findFirstChild'right_arml'or'weld'){
  406. name='right_arml';
  407. part0=torso;
  408. part1=arm;
  409. torso;
  410. };
  411.  
  412. arml=(arml or 0)+1;
  413. local alv=arml;
  414. local gyro=torso:findFirstChild'p_gyro'or Instance.new('BodyGyro',torso);
  415. gyro.maxTorque=Vector3.new(5e5,5e5,5e5);
  416. gyro.P=30000;
  417. gyro.D=1000;
  418. gyro.Name='p_gyro';
  419. repeat
  420. local pos=mouse.hit.p;
  421. local val,valp,p0,p1,p2,hitpos,cj,c0,c1;
  422.  
  423. val=-math.pi*0.5;
  424. valp=val*-1;
  425. p0=torso.CFrame;
  426. p0=p0+((p0*CFrame.Angles(valp,0,0)).lookVector*0.5)+(p0*CFrame.Angles(0,val,0)).lookVector;
  427. p1=p0+((p0.p-pos).unit*-2);
  428. p2=CFrame.new((p0.p+p1.p)/2,p0.p)*CFrame.Angles(val,val,0);
  429. hitpos=torso.Position;
  430. cj=CFrame.new(hitpos);
  431. c0=torso.CFrame:inverse()*cj;
  432. c1=p2:inverse()*cj;
  433. weld.C0=c0;
  434. weld.C1=c1;
  435.  
  436. gyro.cframe=CFrame.new(torso.Position,Vector3.new(pos.X,torso.Position.Y,pos.Z));
  437.  
  438. wait(0.001);
  439. until arml~=alv;
  440. gyro.Parent=nil;
  441. end;
  442. end;
  443.  
  444. _cf_deselect=function()
  445. bool_active=false;
  446. arml=(arml or 0)+1;
  447. loop_shot=(loop_shot or 0)+1;
  448.  
  449. h_weld.Part0=torso;
  450. h_weld.C1=h_weld_cf_inactive;
  451.  
  452. local weld=torso:findFirstChild'right_arml';
  453. if(weld)then
  454. weld.Part1=nil;
  455. weld.Part0=nil;
  456. end;
  457. local arm=char:findFirstChild'Right Arm';
  458. local weld=torso:findFirstChild'Right Shoulder';
  459. if(arm and weld)then
  460. weld.Part0=torso;
  461. weld.Part1=arm;
  462. end;
  463. end;
  464.  
  465. _cf_mouse=function(event,fun)
  466. mouse[event:sub(1,1):upper()..event:sub(2)]:connect(function(...)
  467. if(bool_active)then
  468. fun(...);
  469. end;
  470. end);
  471. end;
  472.  
  473.  
  474. do
  475. local main=getfenv(0);
  476. local c=game:children();
  477. local check=function(v)
  478. if(v.className~=''and v.className~='Instance'and game:service(v.className))then
  479. main[v.className:sub(1,1):lower()..v.className:sub(2)]=v;
  480. end;
  481. end;
  482. for i=1,#c do
  483. pcall(check,c[i]);
  484. end;
  485. end;
  486.  
  487.  
  488. bullets={
  489. maximum=33;
  490. current=33;
  491. clip=600;
  492. };
  493.  
  494. list_base_props={
  495. backgroundColor3=_RGB(0,0,0);
  496. textColor3=_RGB(200,200,200);
  497. borderSizePixel=0;
  498. color=_RGB(0,0,0);
  499. archivable=false;
  500. canCollide=false;
  501. bottomSurface=0;
  502. topSurface=0;
  503. formFactor=0;
  504. locked=true;
  505. };
  506.  
  507.  
  508.  
  509. user=players.localPlayer;
  510. mouse=user:getMouse();
  511. char=user.Character;
  512. gui=user.PlayerGui;
  513. bag=user.Backpack;
  514. torso=char.Torso;
  515. head=char.Head;
  516. hum=_hum(char);
  517.  
  518. url='rbxassetid://%d';
  519. name='GLOCK 18 Machine Pistol';
  520.  
  521. h_weld_cf_inactive=_cframe(0.35,0.5,0.5,
  522. 0,90,-70);
  523. h_weld_cf_active=_cframe(0,0.75,0,
  524. -110,180,0);
  525.  
  526. assert(hum,'humanoid is not found');
  527.  
  528.  
  529.  
  530. _clear();
  531.  
  532.  
  533. _cf_mouse('button1Down',function()
  534. loop_shot=(loop_shot or 0)+1;
  535. local vers=loop_shot;
  536. local step=runService.Stepped;
  537. repeat
  538. _shot((tube.CFrame*CFrame.new(0,0,tube.Size.Z*0.5)).p,mouse.hit.p);
  539. step:wait(0.005);--wait(0.001);
  540. until vers~=loop_shot;
  541. end);
  542.  
  543. _cf_mouse('button1Up',function()
  544. loop_shot=(loop_shot or 0)+1;
  545. end);
  546.  
  547. _cf_mouse('move',function()
  548. cross_f.Position=UDim2.new(0,mouse.X-11,0,mouse.Y-11);
  549. end);
  550.  
  551. _cf_mouse('keyDown',function(k)
  552. if(k=='r')then
  553. if(bullets.clip>0 and time_left<=time())then
  554. local got=(bullets.clip>bullets.maximum and
  555. bullets.maximum or
  556. bullets.clip)-bullets.current;
  557.  
  558. bullets.clip=bullets.clip-got;
  559. bullets.current=bullets.current+got;
  560. if(got~=0)then
  561. time_left=time()+2;
  562. end;
  563. end;
  564. end;
  565. end);
  566.  
  567.  
  568. screen=_new'screenGui'{
  569. name=name;
  570. };
  571.  
  572. cross_f=_new'frame'{
  573. size=UDim2.new(0,21,0,21);
  574. backgroundTransparency=1;
  575. screen;
  576. };
  577.  
  578. for i=0,1 do
  579. _new'frame'{
  580. position=UDim2.new(0,13*i,0,11);
  581. size=UDim2.new(0,10,0,1);
  582. cross_f;
  583. };
  584. end;
  585.  
  586. for i=0,1 do
  587. _new'frame'{
  588. position=UDim2.new(0,11,0,13*i);
  589. size=UDim2.new(0,1,0,10);
  590. cross_f;
  591. };
  592. end;
  593.  
  594.  
  595.  
  596. shot_sound=_new(head:findFirstChild'2920959'or'sound'){
  597. soundId=url:format(2920959);
  598. pitch=1.4;
  599. head;
  600. };
  601. if(shot_sound.Name~='2920959')then
  602. shot_sound.Name='2920959';
  603. shot_sound:play();
  604. end;
  605.  
  606. bin=_new'hopperBin'{
  607. deselected=_cf_deselect;
  608. selected=_cf_select;
  609. name=name;
  610. bag;
  611. };
  612.  
  613. inv=_new'model'{
  614. name=name;
  615. char;
  616. };
  617.  
  618. handle=_new'part'{
  619. size=Vector3.new(0.3,1.3,0.4);
  620. color=_RGB(140,140,140);
  621. name='handle';
  622. material='Metal';
  623. formFactor=3;
  624. inv;
  625. touched=function(hit)
  626. if(hit.Parent.className=='Model')then
  627. local hum=_hum(hit.Parent);
  628. if(hum~=nil)then
  629. _hum_dam(hum,handle.Velocity.magnitude);
  630. end;
  631. end;
  632. end;
  633. };
  634. h_weld=_new'weld'{
  635. c1=h_weld_cf_inactive;
  636. part1=handle;
  637. part0=torso;
  638. handle;
  639. };
  640. _make_hue();
  641.  
  642. h_part=_new'part'{
  643. size=Vector3.new(0.4,0.4,1.4);
  644. color=_RGB(140,140,140);
  645. name='handle';
  646. formFactor=3;
  647. handle;
  648. };
  649. hp_weld=_new'weld'{
  650. c1=_cframe(0,-1.3/2,-0.3,
  651. 20,0,0);
  652. part0=handle;
  653. part1=h_part;
  654. handle;
  655. };
  656.  
  657. drag=_new'part'{
  658. size=Vector3.new(0.5,0.45,1.5);
  659. color=_RGB(100,100,100);
  660. name='handle';
  661. formFactor=3;
  662. handle;
  663. };
  664. d_weld=_new'weld'{
  665. c1=_cframe(0,-0.25,0);
  666. part0=h_part;
  667. part1=drag;
  668. handle;
  669. };
  670.  
  671. tube=_new'part'{
  672. size=Vector3.new(0.2,0.2,1.5);
  673. color=_RGB(0,0,0);
  674. name='handle';
  675. formFactor=3;
  676. handle;
  677. };
  678. t_weld=_new'weld'{
  679. c1=_cframe(0,-0.3,-0.1);
  680. part0=h_part;
  681. part1=tube;
  682. handle;
  683. };
  684.  
  685. bullets_label=_new'textLabel'{
  686. textStrokeColor3=_RGB(0,0,0);
  687. textColor3=_RGB(200,200,200);
  688. textStrokeTransparency=0;
  689. backgroundTransparency=1;
  690. fontSize=5;
  691. screen;
  692. };
  693.  
  694. lightstuff=_new'frame'{
  695. backgroundColor3=_RGB(255,255,255);
  696. position=UDim2.new(0,0,0,-1);
  697. backgroundTransparency=0.5;
  698. size=UDim2.new(1,0,1,1);
  699. borderSizePixel=0;
  700. visible=false;
  701. screen;
  702. };
  703.  
  704. coroutine.wrap(function()
  705. local red,white,green;
  706. repeat
  707. if(screen.Parent)then
  708. if(not green and bullets.current==bullets.maximum)then
  709. green=true;
  710. bullets_label.TextColor3=_RGB(0,200,0);
  711. elseif(not red and bullets.current==0)then
  712. red=true;
  713. bullets_label.TextColor3=_RGB(200,0,0);
  714. elseif((red or green)and bullets.current~=0 and bullets.current~=bullets.maximum)then
  715. bullets_label.TextColor3=_RGB(200,200,200);
  716. green=false;
  717. red=false;
  718. end;
  719. bullets_label.Text=('Bullets: '..bullets.current..'/'..bullets.clip..""):format(bullets.current,bullets.clip);
  720. bullets_label.Size=UDim2.new(0,bullets_label.TextBounds.X,0,bullets_label.TextBounds.Y);
  721. bullets_label.Position=UDim2.new(1,-bullets_label.TextBounds.X-6,1,-bullets_label.TextBounds.Y-6);
  722. end;
  723. wait(0.001);
  724. until nil;
  725. end)();
  726.  
  727.  
  728. _G.dev_pistol_version=(_G.dev_pistol_version or 0)+1;
  729. local vers=_G.dev_pistol_version;
  730. repeat _update();wait(0.001);until _G.dev_pistol_version~=vers or hum.Health==0;
  731. if(hum.Health==0)then
  732. _clear();
  733. end;
Add Comment
Please, Sign In to add comment