Advertisement
Delros12

Tank Script

May 26th, 2018 (edited)
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.97 KB | None | 0 0
  1. -- useful functions
  2. function setValue(name, parent, vector3val)
  3.     local posVal = Instance.new("Vector3Value", parent)
  4.     posVal.Name = name
  5.     posVal.Value = vector3val
  6.     return posVal
  7. end
  8.  
  9. function rotationDifference(angle1, angle2)
  10.     local difference = {x = 0, y = 0, z = 0}
  11.  
  12.     difference.x = angle2.x - angle1.x
  13.     if difference.x > 180 then
  14.         difference.x = difference.x - 360
  15.     elseif difference.x < -180 then
  16.         difference.x = difference.x + 360
  17.     end
  18.  
  19.     difference.y = angle2.y - angle1.y
  20.     if difference.y > 180 then
  21.         difference.y = difference.y - 360
  22.     elseif difference.y < -180 then
  23.         difference.y = difference.y + 360
  24.     end
  25.  
  26.     difference.z = angle2.z - angle1.z
  27.     if difference.z > 180 then
  28.         difference.z = difference.z - 360
  29.     elseif difference.z < -180 then
  30.         difference.z = difference.z + 360
  31.     end
  32.    
  33.     return Vector3.new(difference.x, difference.y, difference.z)
  34. end
  35.  
  36. function angleDifference(angle1, angle2)
  37.     local difference = 0
  38.  
  39.     difference = angle2 - angle1
  40.     if difference > 180 then
  41.         difference = difference - 360
  42.     elseif difference < -180 then
  43.         difference = difference + 360
  44.     end
  45.    
  46.     return difference
  47. end
  48.  
  49. function weldToHumRoot(part, humroot)
  50.     local rweld = Instance.new("Weld", humroot)
  51.     rweld.Part0 = humroot
  52.     rweld.Part1 = part
  53.    
  54.     return rweld
  55. end
  56. --
  57.  
  58. local player = game.Players.LocalPlayer
  59. local char = player.Character
  60. local camera = workspace.Camera
  61.  
  62. repeat wait()
  63.     char = player.Character
  64. until char
  65.  
  66. local model = Instance.new("Model", game.Lighting)
  67. local mouse = player:GetMouse()
  68.  
  69. local p1 = Instance.new("Part", model)
  70. p1.BrickColor = BrickColor.new("Dark stone grey")
  71. p1.Material = "Metal"
  72. p1.Anchored = true
  73. p1.Shape = "Cylinder"
  74. p1.Size = Vector3.new(1, 0.9, 0.9)
  75. p1.CFrame = CFrame.new(-0.05, 0.81, -13.3) *
  76.             CFrame.Angles(math.rad(-180), math.rad(0), math.rad(-180))
  77. local p2 = Instance.new("Part", model)
  78. p2.BrickColor = BrickColor.new("Dark stone grey")
  79. p2.Material = "Metal"
  80. p2.Anchored = true
  81. p2.Shape = "Cylinder"
  82. p2.Size = Vector3.new(1, 0.9, 0.9)
  83. p2.CFrame = CFrame.new(-0.05, 0.81, -14.3) *
  84.             CFrame.Angles(math.rad(-180), math.rad(0), math.rad(-180))
  85. local p3 = Instance.new("Part", model)
  86. p3.BrickColor = BrickColor.new("Dark stone grey")
  87. p3.Material = "Metal"
  88. p3.Anchored = true
  89. p3.Shape = "Cylinder"
  90. p3.Size = Vector3.new(1, 0.9, 0.9)
  91. p3.CFrame = CFrame.new(-0.05, 0.81, -12.3) *
  92.             CFrame.Angles(math.rad(-180), math.rad(0), math.rad(-180))
  93. local p4 = Instance.new("Part", model)
  94. p4.BrickColor = BrickColor.new("Dark stone grey")
  95. p4.Material = "Metal"
  96. p4.Anchored = true
  97. p4.Shape = "Cylinder"
  98. p4.Size = Vector3.new(1, 0.9, 0.9)
  99. p4.CFrame = CFrame.new(2.05, 0.81, -13.3) *
  100.             CFrame.Angles(math.rad(-180), math.rad(0), math.rad(-180))
  101. local p5 = Instance.new("Part", model)
  102. p5.BrickColor = BrickColor.new("Dark stone grey")
  103. p5.Material = "Metal"
  104. p5.Anchored = true
  105. p5.Shape = "Cylinder"
  106. p5.Size = Vector3.new(1, 0.9, 0.9)
  107. p5.CFrame = CFrame.new(2.05, 0.81, -14.3) *
  108.             CFrame.Angles(math.rad(-180), math.rad(0), math.rad(-180))
  109. local p6 = Instance.new("Part", model)
  110. p6.BrickColor = BrickColor.new("Dark stone grey")
  111. p6.Material = "Metal"
  112. p6.Anchored = true
  113. p6.Shape = "Cylinder"
  114. p6.Size = Vector3.new(1, 0.9, 0.9)
  115. p6.CFrame = CFrame.new(2.05, 0.81, -12.3) *
  116.             CFrame.Angles(math.rad(-180), math.rad(0), math.rad(-180))
  117. local p7 = Instance.new("Part", model)
  118. p7.BrickColor = BrickColor.new("Really black")
  119. p7.Material = "SmoothPlastic"
  120. p7.Anchored = true
  121. p7.Shape = "Block"
  122. p7.Size = Vector3.new(2, 1, 1)
  123. p7.CFrame = CFrame.new(2, 0.81, -13.3) *
  124.             CFrame.Angles(math.rad(0), math.rad(90), math.rad(0))
  125. local p8 = Instance.new("Part", model)
  126. p8.BrickColor = BrickColor.new("Really black")
  127. p8.Material = "SmoothPlastic"
  128. p8.Anchored = true
  129. p8.Shape = "Cylinder"
  130. p8.Size = Vector3.new(1, 1, 1)
  131. p8.CFrame = CFrame.new(2, 0.81, -12.3) *
  132.             CFrame.Angles(math.rad(-180), math.rad(0), math.rad(-180))
  133. local p9 = Instance.new("Part", model)
  134. p9.BrickColor = BrickColor.new("Really black")
  135. p9.Material = "SmoothPlastic"
  136. p9.Anchored = true
  137. p9.Shape = "Block"
  138. p9.Size = Vector3.new(2, 1, 1)
  139. p9.CFrame = CFrame.new(0, 0.81, -13.3) *
  140.             CFrame.Angles(math.rad(0), math.rad(90), math.rad(0))
  141. local p10 = Instance.new("Part", model)
  142. p10.BrickColor = BrickColor.new("Really black")
  143. p10.Material = "SmoothPlastic"
  144. p10.Anchored = true
  145. p10.Shape = "Cylinder"
  146. p10.Size = Vector3.new(1, 1, 1)
  147. p10.CFrame = CFrame.new(0, 0.81, -14.3) *
  148.             CFrame.Angles(math.rad(-180), math.rad(0), math.rad(-180))
  149. local p11 = Instance.new("Part", model)
  150. p11.BrickColor = BrickColor.new("Really black")
  151. p11.Material = "SmoothPlastic"
  152. p11.Anchored = true
  153. p11.Shape = "Cylinder"
  154. p11.Size = Vector3.new(1, 1, 1)
  155. p11.CFrame = CFrame.new(2, 0.81, -14.3) *
  156.             CFrame.Angles(math.rad(-180), math.rad(0), math.rad(-180))
  157. local p12 = Instance.new("Part", model)
  158. p12.BrickColor = BrickColor.new("Really black")
  159. p12.Material = "SmoothPlastic"
  160. p12.Anchored = true
  161. p12.Shape = "Cylinder"
  162. p12.Size = Vector3.new(1, 1, 1)
  163. p12.CFrame = CFrame.new(0, 0.81, -12.3) *
  164.             CFrame.Angles(math.rad(-180), math.rad(0), math.rad(-180))
  165. local p13 = Instance.new("Part", model)
  166. p13.BrickColor = BrickColor.new("Medium stone grey")
  167. p13.Material = "Metal"
  168. p13.Anchored = true
  169. p13.Shape = "Block"
  170. p13.Size = Vector3.new(0.8, 0.2, 1)
  171. p13.CFrame = CFrame.new(2, 1.41, -12.6) *
  172.             CFrame.Angles(math.rad(0), math.rad(90), math.rad(0))
  173. local p14 = Instance.new("Part", model)
  174. p14.BrickColor = BrickColor.new("Medium stone grey")
  175. p14.Material = "Metal"
  176. p14.Anchored = true
  177. p14.Shape = "Block"
  178. p14.Size = Vector3.new(0.8, 0.2, 1)
  179. p14.CFrame = CFrame.new(0, 1.41, -12.6) *
  180.             CFrame.Angles(math.rad(0), math.rad(90), math.rad(0))
  181. local p15 = Instance.new("Part", model)
  182. p15.BrickColor = BrickColor.new("Medium stone grey")
  183. p15.Material = "Metal"
  184. p15.Anchored = true
  185. p15.Shape = "Block"
  186. p15.Size = Vector3.new(0.2, 0.7, 0.8)
  187. p15.CFrame = CFrame.new(1, 1.06, -12.2) *
  188.             CFrame.Angles(math.rad(0), math.rad(90), math.rad(0))
  189. local p16 = Instance.new("Part", model)
  190. p16.BrickColor = BrickColor.new("Medium stone grey")
  191. p16.Material = "Metal"
  192. p16.Anchored = true
  193. p16.Shape = "Block"
  194. p16.Size = Vector3.new(1.2, 0.9, 1)
  195. p16.CFrame = CFrame.new(1, 1.06, -12.8) *
  196.             CFrame.Angles(math.rad(0), math.rad(90), math.rad(0))
  197. local p17 = Instance.new("WedgePart", model)
  198. p17.BrickColor = BrickColor.new("Medium stone grey")
  199. p17.Material = "Metal"
  200. p17.Anchored = true
  201. p17.Size = Vector3.new(1, 0.4, 1.1)
  202. p17.CFrame = CFrame.new(1, 0.81, -13.95) *
  203.             CFrame.Angles(math.rad(0), math.rad(0), math.rad(-180))
  204. local p18 = Instance.new("WedgePart", model)
  205. p18.BrickColor = BrickColor.new("Medium stone grey")
  206. p18.Material = "Metal"
  207. p18.Anchored = true
  208. p18.Size = Vector3.new(1, 0.2, 0.7)
  209. p18.CFrame = CFrame.new(2, 1.41, -13.35) *
  210.             CFrame.Angles(math.rad(0), math.rad(0), math.rad(0))
  211. local p19 = Instance.new("WedgePart", model)
  212. p19.BrickColor = BrickColor.new("Medium stone grey")
  213. p19.Material = "Metal"
  214. p19.Anchored = true
  215. p19.Size = Vector3.new(1, 0.5, 1.1)
  216. p19.CFrame = CFrame.new(1, 1.26, -13.95) *
  217.             CFrame.Angles(math.rad(0), math.rad(0), math.rad(0))
  218. local p20 = Instance.new("WedgePart", model)
  219. p20.BrickColor = BrickColor.new("Medium stone grey")
  220. p20.Material = "Metal"
  221. p20.Anchored = true
  222. p20.Size = Vector3.new(1, 0.2, 0.7)
  223. p20.CFrame = CFrame.new(0, 1.41, -13.35) *
  224.             CFrame.Angles(math.rad(0), math.rad(0), math.rad(0))
  225. local p21 = Instance.new("Part", model)
  226. p21.BrickColor = BrickColor.new("Medium stone grey")
  227. p21.Material = "Metal"
  228. p21.Anchored = true
  229. p21.Shape = "Cylinder"
  230. p21.Size = Vector3.new(0.8, 0.2, 0.2)
  231. p21.CFrame = CFrame.new(1.4, 1.01, -12.2) *
  232.             CFrame.Angles(math.rad(180), math.rad(0), math.rad(90))
  233. local p22 = Instance.new("Part", model)
  234. p22.BrickColor = BrickColor.new("Medium stone grey")
  235. p22.Material = "Metal"
  236. p22.Anchored = true
  237. p22.Shape = "Cylinder"
  238. p22.Size = Vector3.new(0.8, 0.2, 0.2)
  239. p22.CFrame = CFrame.new(0.6, 1.01, -12.2) *
  240.             CFrame.Angles(math.rad(180), math.rad(0), math.rad(90))
  241. local p23 = Instance.new("Part", model)
  242. p23.BrickColor = BrickColor.new("Medium stone grey")
  243. p23.Material = "Metal"
  244. p23.Anchored = true
  245. p23.Shape = "Cylinder"
  246. p23.Size = Vector3.new(0.8, 0.2, 0.2)
  247. p23.CFrame = CFrame.new(1, 0.71, -12.2) *
  248.             CFrame.Angles(math.rad(-180), math.rad(0), math.rad(-180))
  249. local p24 = Instance.new("Part", model)
  250. p24.BrickColor = BrickColor.new("Medium stone grey")
  251. p24.Material = "Metal"
  252. p24.Anchored = true
  253. p24.Shape = "Cylinder"
  254. p24.Size = Vector3.new(3, 0.2, 0.2)
  255. p24.CFrame = CFrame.new(1, 1.41, -12.2) *
  256.             CFrame.Angles(math.rad(-180), math.rad(0), math.rad(-180))
  257.  
  258. --
  259. local p25 = Instance.new("Part", model)
  260. p25.Name = "RotatingTurret"
  261. p25.BrickColor = BrickColor.new("Medium stone grey")
  262. p25.Material = "Metal"
  263. p25.Anchored = true
  264. p25.Shape = "Cylinder"
  265. p25.Size = Vector3.new(0.1, 0.5, 0.5)
  266. p25.CFrame = CFrame.new(1, 1.56, -12.8) *
  267.             CFrame.Angles(math.rad(0), math.rad(-90), math.rad(90))
  268.            
  269. local p26 = Instance.new("Part", p25)
  270. p26.Name = "TurretPart"
  271. p26.BrickColor = BrickColor.new("Medium stone grey")
  272. p26.Material = "Metal"
  273. p26.Anchored = true
  274. p26.Shape = "Block"
  275. p26.Size = Vector3.new(1, 0.6, 1)
  276.  
  277. setValue("PosVal", p26, Vector3.new(0.25, 0, 0))
  278. setValue("RotVal", p26, Vector3.new(0, 0, 90))
  279.  
  280. local p27 = Instance.new("Part", p26)
  281. p27.Name = "RotatingBarrel"
  282. p27.BrickColor = BrickColor.new("Medium stone grey")
  283. p27.Material = "Metal"
  284. p27.Anchored = true
  285. p27.Shape = "Ball"
  286. p27.Size = Vector3.new(0.4, 0.4, 0.4)
  287.  
  288. setValue("PosVal", p27, Vector3.new(0.5, 0, 0))
  289. setValue("RotVal", p27, Vector3.new(0, 0, 0))
  290.  
  291. local p28 = Instance.new("Part", p27)
  292. p28.Name = "TurretBarrelPart"
  293. p28.BrickColor = BrickColor.new("Medium stone grey")
  294. p28.Material = "Metal"
  295. p28.Anchored = true
  296. p28.Shape = "Cylinder"
  297. p28.Size = Vector3.new(1.2, 0.4, 0.4)
  298.  
  299. setValue("PosVal", p28, Vector3.new(0.6, 0, 0))
  300. setValue("RotVal", p28, Vector3.new(0, 0, 0))
  301.  
  302. local p29 = Instance.new("Part", p27)
  303. p29.Name = "TurretBarrelPart"
  304. p29.BrickColor = BrickColor.new("Medium stone grey")
  305. p29.Material = "Metal"
  306. p29.Anchored = true
  307. p29.Shape = "Cylinder"
  308. p29.Size = Vector3.new(0.5, 0.475, 0.475)
  309.  
  310. setValue("PosVal", p29, Vector3.new(1, 0, 0))
  311. setValue("RotVal", p29, Vector3.new(0, 0, 0))
  312.  
  313. local p30 = Instance.new("Part", p27)
  314. p30.Name = "TurretBarrelExit"
  315. p30.Color = Color3.new(0, 0, 0)
  316. p30.Material = "SmoothPlastic"
  317. p30.Anchored = true
  318. p30.Shape = "Cylinder"
  319. p30.Size = Vector3.new(0.05, 0.3, 0.3)
  320.  
  321. setValue("PosVal", p30, Vector3.new(1.23, 0, 0))
  322. setValue("RotVal", p30, Vector3.new(0, 0, 0))
  323. --
  324.  
  325. local turrets = {}
  326.            
  327. local rfp = CFrame.new(1, 1, -13)
  328.  
  329. char.HumanoidRootPart.Size = Vector3.new(1, 0, 1)
  330.  
  331. weldToHumRoot(char.HumanoidRootPart, char.Torso)
  332.  
  333. char.Torso.Neck.C1 = CFrame.new(0, 0, 0)
  334. char.Torso.Neck.C0 = CFrame.new(0, 0, 0)
  335.  
  336. local clonedNeck = char.Torso.Neck:Clone()
  337.  
  338. char.Head.Size = Vector3.new(0, 0, 0)
  339. char.Torso.Size = Vector3.new(0, 0, 0)
  340. clonedNeck.Parent = char.Torso
  341.  
  342. weldToHumRoot(char.Torso, char.HumanoidRootPart)
  343.  
  344. char.Humanoid.HipHeight = 0.67
  345.  
  346. --char.Torso.Size = Vector3.new(1, 0, 1)
  347. --weldToHumRoot(char.Torso, char.HumanoidRootPart)
  348.  
  349. --local mseUnitRot, mseAngle -- don't mind this
  350.  
  351. --local mouseAngle -- the angle of the mouse
  352. function Update()
  353.     --local mseUnitRot, mseAngle = CFrame.new(camera.CFrame.p, mouse.Hit.p):toAxisAngle()
  354.    
  355.     --local mouseAngle = mseUnitRot * math.deg(mseAngle)
  356.    
  357.     --print("Mouse Rotation: " .. mouseAngle.Y .. ", " .. mouseAngle.X)
  358.    
  359.     for _,weld in pairs(turrets) do
  360.         local mseUnitRot, mseAngle = CFrame.new(weld.Parent.CFrame.p, mouse.Hit.p):toAxisAngle()
  361.        
  362.         local mouseAngle = mseUnitRot * math.deg(mseAngle)
  363.        
  364.         weld.C0 = CFrame.Angles(-math.rad(angleDifference(char.HumanoidRootPart.Orientation.Y, mouseAngle.Y)), 0, 0)
  365.         for _,bweld in pairs(weld:GetChildren()) do
  366.             if bweld.Name == "Barrel" and bweld:IsA("ValueBase") then
  367.                 mseUnitRot, mseAngle = CFrame.new(bweld.Value.Parent.CFrame.p, mouse.Hit.p):toAxisAngle()
  368.        
  369.                 mouseAngle = mseUnitRot * math.deg(mseAngle)               
  370.                
  371.                 bweld.Value.C0 = CFrame.Angles(0, 0, math.rad(angleDifference(char.HumanoidRootPart.Orientation.X, mouseAngle.X)))
  372.             end
  373.         end
  374.     end
  375. end
  376.  
  377. Update()
  378. game:GetService("RunService").RenderStepped:connect(Update)
  379.  
  380. for _,v in pairs(model:GetChildren()) do
  381.     if v:IsA("BasePart") then
  382.         local part = v:Clone()
  383.         part.Parent = char
  384.         part.Anchored = false
  385.         local weld = Instance.new("Weld", part)
  386.         weld.Part0 = part
  387.         weld.Part1 = char.Torso
  388.         weld.C1 = CFrame.new(v.CFrame.X - rfp.X,
  389.             v.CFrame.Y - rfp.Y,
  390.             v.CFrame.Z - rfp.Z)
  391.             *
  392.             CFrame.Angles(math.rad(v.Rotation.X), math.rad(v.Rotation.Y), math.rad(v.Rotation.Z))
  393.        
  394.         if part.Name == "RotatingTurret" then
  395.             turrets[table.getn(turrets) + 1] = weld
  396.             for _,trrt in pairs(part:GetChildren()) do
  397.                 if trrt:IsA("BasePart") then
  398.                     print("turret adedd")                  
  399.                    
  400.                     trrt.Anchored = false
  401.                     local tweld = Instance.new("Weld", trrt)
  402.                     tweld.Part0 = trrt
  403.                     tweld.Part1 = part
  404.                     tweld.C1 = CFrame.new(trrt.PosVal.Value.X,
  405.                         trrt.PosVal.Value.Y,
  406.                         trrt.PosVal.Value.Z)
  407.                         *
  408.                         CFrame.Angles(math.rad(trrt.RotVal.Value.X), math.rad(trrt.RotVal.Value.Y), math.rad(trrt.RotVal.Value.Z))
  409.                    
  410.                     local turretCount = table.getn(turrets)
  411.                     for _,rotbrrl in pairs(trrt:GetChildren()) do
  412.                         if rotbrrl:IsA("BasePart") then
  413.                             rotbrrl.Anchored = false
  414.                             local bweld = Instance.new("Weld", rotbrrl)
  415.                             bweld.Part0 = rotbrrl
  416.                             bweld.Part1 = trrt
  417.                             bweld.C1 = CFrame.new(rotbrrl.PosVal.Value.X,
  418.                                 rotbrrl.PosVal.Value.Y,
  419.                                 rotbrrl.PosVal.Value.Z)
  420.                                 *
  421.                                 CFrame.Angles(math.rad(rotbrrl.RotVal.Value.X), math.rad(rotbrrl.RotVal.Value.Y), math.rad(rotbrrl.RotVal.Value.Z))
  422.                            
  423.                             local brrlRef = Instance.new("ObjectValue", turrets[turretCount])
  424.                             brrlRef.Name = "Barrel"
  425.                             brrlRef.Value = bweld
  426.                            
  427.                             for _,brrlpart in pairs(rotbrrl:GetChildren()) do
  428.                                 if brrlpart:IsA("BasePart") then
  429.                                     brrlpart.Anchored = false
  430.                                     local bpweld = Instance.new("Weld", rotbrrl)
  431.                                     bpweld.Part0 = brrlpart
  432.                                     bpweld.Part1 = rotbrrl
  433.                                     bpweld.C1 = CFrame.new(brrlpart.PosVal.Value.X,
  434.                                         brrlpart.PosVal.Value.Y,
  435.                                         brrlpart.PosVal.Value.Z)
  436.                                         *
  437.                                         CFrame.Angles(math.rad(brrlpart.RotVal.Value.X), math.rad(brrlpart.RotVal.Value.Y), math.rad(brrlpart.RotVal.Value.Z))
  438.                                     if brrlpart.Name == "TurretBarrelExit" then
  439.                                         setValue("ExitPos", rotbrrl, brrlpart.PosVal.Value)
  440.                                     end
  441.                                 end
  442.                             end
  443.                         end
  444.                     end
  445.                 end
  446.             end
  447.         end
  448.     end
  449. end
  450.  
  451. char.Humanoid.WalkSpeed = 24
  452. char.Humanoid.MaxHealth = 400
  453. char.Humanoid.Health = char.Humanoid.MaxHealth
  454. char.Head.Transparency = 1
  455. char.Torso.Transparency = 1
  456. char["Right Leg"]:Destroy()
  457. char["Left Leg"]:Destroy()
  458. char["Right Arm"]:Destroy()
  459. char["Left Arm"]:Destroy()
  460. char.Head:WaitForChild("face"):Destroy()
  461. for _,h in pairs(char:GetChildren()) do
  462.     if h.ClassName == "Accessory" then h:Destroy() end
  463. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement