Laith8888

Roblox Draw Tool script

Feb 6th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1. players = game.Players
  2. user=players.LocalPlayer;
  3. uname=user.Name;
  4. guis=user.PlayerGui;
  5. pack=user.Backpack;
  6. keyDowns={};
  7. freeKeys={};
  8. shortcuts={};
  9. _G.mine=_G.mine or{};
  10. name='Draw3D';
  11. url='http://www.roblox.com/asset/?id=%d';
  12. iconNormal=url:format(96578285);
  13. iconOnDown=url:format(96584484);
  14. ver=0;
  15. drawPixel=0.10;
  16. _G.drawLimit=_G.drawLimit or 1000;
  17. _G.drawColor=_G.drawColor or Color3.new();
  18. destroy=game.remove;
  19. find=game.findFirstChild;
  20. new=Instance.new;
  21. with=function(c)
  22. return function(p)
  23. local o=type(c)=='string'and new(c)or c;
  24. local x=p.Parent;p.Parent=nil;
  25. for i,v in next,p do
  26. o[i]=v;
  27. end;
  28. if(x)then
  29. o.Parent=x;
  30. end;
  31. return o;
  32. end;
  33. end;
  34. getPlace=function()
  35. if(find(workspace,'draw')==nil)then
  36. new('Model',workspace).Name='draw';
  37. end;
  38. if(find(workspace.draw,uname)==nil)then
  39. new('Model',workspace.draw).Name=uname;
  40. end;
  41. return workspace.draw[uname];
  42. end;
  43. drawLine=function(start,target)
  44. local gui=with'BlockMesh'{
  45. Parent=with'Part'{
  46. CFrame=CFrame.new(start,target)*CFrame.new(0,0,-(start-target).magnitude/2);
  47. Size=Vector3.new(drawPixel,drawPixel,(start-target).magnitude+.325*drawPixel);
  48. Parent=getPlace();
  49. Color=_G.drawColor;
  50. BottomSurface=0;
  51. Anchored=true;
  52. TopSurface=0;
  53. formFactor=3;
  54. Name=name;
  55. }}.Parent;
  56. table.insert(_G.mine,gui);
  57. return gui;
  58. end;
  59. onDown=function()
  60. if(drawing)then
  61. return nil;
  62. end;
  63. if(selectGui.Adornee)then
  64. destroy(selectGui.Adornee);
  65. end;
  66.  
  67. drawing=true;
  68.  
  69. mouse.Icon=iconOnDown;
  70. ver=ver+1;
  71.  
  72.  
  73. local cVer,start,target=ver,mouse.hit.p;
  74.  
  75. local group={};
  76. repeat
  77. Wait(0.02);
  78.  
  79. if(mouse.target and mouse.target.Name~=name and mouse.hit.p~=start)then
  80.  
  81. target=mouse.hit.p;
  82.  
  83. table.insert(group,drawLine(start,target));
  84.  
  85. start=target;
  86. end;
  87. until ver~=cVer;
  88. drawing=false;
  89.  
  90. local groupM=new('Model',getPlace());
  91. for i,v in next,group do
  92. if(v:IsDescendantOf(Workspace))then
  93. v.Parent=groupM;
  94. end;
  95. end;
  96. if(next(groupM:children())==nil)then
  97. destroy(groupM);
  98. end;
  99. end;
  100. onUp=function()
  101. mouse.Icon=iconNormal;
  102. ver=ver+1;
  103. end;
  104. onKeyDown=function(k)
  105. if(freeKeys[k]==false)then
  106. return false;
  107. end;
  108. freeKeys[k]=false;
  109. Wait(0.01);
  110. if(keyDowns[k])then
  111. keyDowns[k]();
  112. elseif(shortcuts[k])then
  113. shortcuts[k]();
  114. end;
  115. end;
  116. onKeyUp=function(k)
  117. freeKeys[k]=true;
  118. end;
  119. onMove=function()
  120. end;
  121. onSelect=function(lmouse)
  122. frame.Visible=true;
  123. mouse=lmouse;
  124.  
  125. mouse.Icon=iconNormal;
  126.  
  127. mouse.Button1Down:connect(onDown);
  128. mouse.KeyDown:connect(onKeyDown);
  129. mouse.Button1Up:connect(onUp);
  130. mouse.KeyUp:connect(onKeyUp);
  131. mouse.Move:connect(onMove);
  132. end;
  133. onDeselect=function()
  134. ver=ver+1;
  135. frame.Visible=false;
  136. selectGui.Adornee=nil;
  137. mouse.Icon=iconNormal;
  138. for i,v in next,freeKeys do
  139. freeKeys[i]=true;
  140. end;
  141. end;
  142. addButton=function(title,shortcut,fun)
  143. with'TextButton'{
  144. Text=string.format(' %s (%s)',title,shortcut);
  145. TextXAlignment=0;
  146. Parent=frame;
  147. }.MouseButton1Up:connect(fun);
  148.  
  149. shortcuts[shortcut]=fun;
  150.  
  151. local c=#frame:children();
  152. for i,v in next,frame:children()do
  153. v.Position=UDim2.new(0,0,0,20*(i-1));
  154. v.Size=UDim2.new(1,0,0,20);
  155. end;
  156.  
  157. frame.Position=UDim2.new(1,-152,.5,-c*10);
  158. frame.Size=UDim2.new(0,150,0,c*20);
  159. end;
  160. for i,v in next,{guis;pack;}do
  161. pcall(function()
  162. repeat until destroy(v[name]);
  163. end);
  164. end;
  165. tool=with'HopperBin'{
  166. Parent=pack;
  167. Name=name;
  168. };
  169. tool.Deselected:connect(onDeselect);
  170. tool.Selected:connect(onSelect);
  171. screen=with'ScreenGui'{
  172. Parent=guis;
  173. Name=name;
  174. };
  175. frame=with'Frame'{
  176. Parent=screen;
  177. Visible=false;
  178. };
  179. clframe=with'Frame'{
  180. Position=UDim2.new(.5,-50,.5,-50);
  181. Size=UDim2.new(0,100,0,100);
  182. Visible=false;
  183. Parent=screen;
  184. };
  185. selectGui=with'SelectionBox'{
  186. Parent=screen;
  187. };
  188. local c=0;
  189. for y=0,7 do
  190. for x=0,7 do
  191. local color=BrickColor.palette(c).Color;
  192.  
  193. with'ImageButton'{
  194. Position=UDim2.new(.125*x,0,.125*y);
  195. Size=UDim2.new(.125,0,.125);
  196. BackgroundColor3=color;
  197. Parent=clframe;
  198. }.MouseButton1Up:connect(function()
  199. clframe.Visible=false;
  200. _G.drawColor=color;
  201. end);
  202.  
  203. c=c+1;
  204. end;
  205. end;
  206. addButton('Color','c',function()
  207. clframe.Visible=true;
  208. end);
  209. addButton('Remove your draws','r',function()
  210. repeat
  211. destroy(_G.mine[1]);
  212. table.remove(_G.mine,1);
  213. Wait(0.01);
  214. until nil;
  215. end);
  216. addButton('Remove global draws','k',function()
  217. destroy(workspace.draw);
  218. while(_G.mine[1])do
  219. destroy(_G.mine[1]);
  220. table.remove(_G.mine,1);
  221. end;
  222. end);
  223. addButton('Remove selected','x',function()
  224. repeat
  225. if(find(workspace,'draw'))then
  226. local dt=mouse.target;
  227. if(dt and dt:IsDescendantOf(workspace.draw))then
  228. selectGui.Adornee=dt.Parent;
  229. else
  230. selectGui.Adornee=nil;
  231. end;
  232. else
  233. selectGui.Adornee=nil;
  234. end;
  235. Wait(0.01);
  236. until freeKeys.x;
  237. selectGui.Adornee=nil;
  238. end);
  239. repeat
  240. Wait(0.01);
  241. if(next(_G.mine)and _G.mine[_G.drawLimit])then
  242. destroy(_G.mine[1]);
  243. table.remove(_G.mine,1);
  244. end;
  245. until script.Parent==nil or tool.Parent==nil;
  246. script.Disabled=true;
  247. destroy(screen);
Add Comment
Please, Sign In to add comment