Advertisement
Animescapetower

laser guns

Mar 16th, 2018
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.95 KB | None | 0 0
  1.  
  2. --Converted with ttyyuu12345's model to script plugin v4
  3. function sandbox(var,func)
  4. local env = getfenv(func)
  5. local newenv = setmetatable({},{
  6. __index = function(self,k)
  7. if k=="script" then
  8. return var
  9. else
  10. return env[k]
  11. end
  12. end,
  13. })
  14. setfenv(func,newenv)
  15. return func
  16. end
  17. cors = {}
  18. mas = Instance.new("Model",game:GetService("Lighting"))
  19. Tool0 = Instance.new("Tool")
  20. Part1 = Instance.new("Part")
  21. SpecialMesh2 = Instance.new("SpecialMesh")
  22. Sound3 = Instance.new("Sound")
  23. Sound4 = Instance.new("Sound")
  24. PointLight5 = Instance.new("PointLight")
  25. LocalScript6 = Instance.new("LocalScript")
  26. Sound7 = Instance.new("Sound")
  27. LocalScript8 = Instance.new("LocalScript")
  28. Tool0.Name = "EVN-34"
  29. Tool0.Parent = mas
  30. Tool0.GripPos = Vector3.new(0, -0.100000001, 1)
  31. Tool0.ToolTip = "SHOT GUN"
  32. Tool0.CanBeDropped = false
  33. Part1.Name = "Handle"
  34. Part1.Parent = Tool0
  35. Part1.FormFactor = Enum.FormFactor.Custom
  36. Part1.Size = Vector3.new(0.580000222, 1.34000099, 2.48000145)
  37. Part1.CFrame = CFrame.new(45.5200005, 0.670031011, 133.390015, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  38. Part1.BottomSurface = Enum.SurfaceType.Smooth
  39. Part1.TopSurface = Enum.SurfaceType.Smooth
  40. Part1.Position = Vector3.new(45.5200005, 0.670031011, 133.390015)
  41. SpecialMesh2.Parent = Part1
  42. SpecialMesh2.MeshId = "http://www.roblox.com/asset?id=139121396"
  43. SpecialMesh2.Scale = Vector3.new(2.5, 2.5, 2.5)
  44. SpecialMesh2.TextureId = "http://www.roblox.com/asset?id=139121368"
  45. SpecialMesh2.MeshType = Enum.MeshType.FileMesh
  46. SpecialMesh2.Scale = Vector3.new(2.5, 2.5, 2.5)
  47. Sound3.Name = "Fire"
  48. Sound3.Parent = Part1
  49. Sound3.SoundId = "http://www.roblox.com/asset?id=130113322"
  50. Sound4.Name = "Reload"
  51. Sound4.Parent = Part1
  52. Sound4.SoundId = "http://www.roblox.com/asset?id=130113370"
  53. PointLight5.Parent = Part1
  54. PointLight5.Color = Color3.new(0, 1, 1)
  55. PointLight5.Range = 6
  56. PointLight5.Color = Color3.new(0, 1, 1)
  57. LocalScript6.Name = "ToolScript"
  58. LocalScript6.Parent = Tool0
  59. table.insert(cors,sandbox(LocalScript6,function()
  60. -----------------
  61. --| Constants |--
  62. -----------------
  63.  
  64. local SHOT_SPEED = 100
  65. local SHOT_TIME = 2
  66.  
  67. local NOZZLE_OFFSET = Vector3.new(0, 0.4, -1.1)
  68.  
  69. local DEBOUNCE_TAG_NAME = 'Busy'
  70.  
  71. -----------------
  72. --| Variables |--
  73. -----------------
  74.  
  75. local PlayersService = Game:GetService('Players')
  76. local DebrisService = Game:GetService('Debris')
  77.  
  78. local Tool = script.Parent
  79. local Handle = Tool:WaitForChild('Handle')
  80.  
  81. local FireSound = Handle:WaitForChild('Fire')
  82. local ReloadSound = Handle:WaitForChild('Reload')
  83. local HitFadeSound = script:WaitForChild('HitFade')
  84.  
  85. local PointLight = Handle:WaitForChild('PointLight')
  86.  
  87. local Character = nil
  88. local Humanoid = nil
  89. local Player = nil
  90.  
  91. local BaseShot = nil
  92.  
  93. -----------------
  94. --| Functions |--
  95. -----------------
  96.  
  97. -- Returns a character ancestor and its Humanoid, or nil
  98. local function FindCharacterAncestor(subject)
  99. if subject and subject ~= Workspace then
  100. local humanoid = subject:FindFirstChild('Humanoid')
  101. if humanoid then
  102. return subject, humanoid
  103. else
  104. return FindCharacterAncestor(subject.Parent)
  105. end
  106. end
  107. return nil
  108. end
  109.  
  110. -- Removes any old creator tags and applies new ones to the specified target
  111. local function ApplyTags(target)
  112. while target:FindFirstChild('creator') do
  113. target.creator:Destroy()
  114. end
  115.  
  116. local creatorTag = Instance.new('ObjectValue')
  117. creatorTag.Value = Player
  118. creatorTag.Name = 'creator' --NOTE: Must be called 'creator' for website stats
  119.  
  120. local iconTag = Instance.new('StringValue')
  121. iconTag.Value = Tool.TextureId
  122. iconTag.Name = 'icon'
  123.  
  124. iconTag.Parent = creatorTag
  125. creatorTag.Parent = target
  126. DebrisService:AddItem(creatorTag, 4)
  127. end
  128.  
  129. -- Returns all objects under instance with Transparency
  130. local function GetTransparentsRecursive(instance, partsTable)
  131. local partsTable = partsTable or {}
  132. for _, child in pairs(instance:GetChildren()) do
  133. if child:IsA('BasePart') or child:IsA('Decal') then
  134. table.insert(partsTable, child)
  135. end
  136. GetTransparentsRecursive(child, partsTable)
  137. end
  138. return partsTable
  139. end
  140.  
  141. local function SelectionBoxify(instance)
  142. local selectionBox = Instance.new('SelectionBox')
  143. selectionBox.Adornee = instance
  144. selectionBox.Color = BrickColor.new('Toothpaste')
  145. selectionBox.Parent = instance
  146. return selectionBox
  147. end
  148.  
  149. local function Light(instance)
  150. local light = PointLight:Clone()
  151. light.Range = light.Range + 2
  152. light.Parent = instance
  153. end
  154.  
  155. local function FadeOutObjects(objectsWithTransparency, fadeIncrement)
  156. repeat
  157. local lastObject = nil
  158. for _, object in pairs(objectsWithTransparency) do
  159. object.Transparency = object.Transparency + fadeIncrement
  160. lastObject = object
  161. end
  162. wait()
  163. until lastObject.Transparency >= 1 or not lastObject
  164. end
  165.  
  166. local function Dematerialize(character, humanoid, firstPart)
  167. local debounceTag = Instance.new('Configuration')
  168. debounceTag.Name = DEBOUNCE_TAG_NAME
  169. debounceTag.Parent = character
  170.  
  171. humanoid.WalkSpeed = 0
  172.  
  173. local parts = {}
  174. for _, child in pairs(character:GetChildren()) do
  175. if child:IsA('BasePart') then
  176. child.Anchored = true
  177. table.insert(parts, child)
  178. elseif child:IsA('LocalScript') or child:IsA('Script') then
  179. child:Destroy()
  180. end
  181. end
  182.  
  183. local selectionBoxes = {}
  184.  
  185. local firstSelectionBox = SelectionBoxify(firstPart)
  186. Light(firstPart)
  187. wait(0.05)
  188.  
  189. for _, part in pairs(parts) do
  190. if part ~= firstPart then
  191. table.insert(selectionBoxes, SelectionBoxify(part))
  192. Light(part)
  193. end
  194. end
  195.  
  196. local objectsWithTransparency = GetTransparentsRecursive(character)
  197. FadeOutObjects(objectsWithTransparency, 0.1)
  198.  
  199. wait(0.5)
  200.  
  201. humanoid.Health = 0
  202. DebrisService:AddItem(character, 2)
  203.  
  204. local fadeIncrement = 0.05
  205. Delay(0.2, function()
  206. FadeOutObjects({firstSelectionBox}, fadeIncrement)
  207. if character then
  208. character:Destroy()
  209. end
  210. end)
  211. FadeOutObjects(selectionBoxes, fadeIncrement)
  212. end
  213.  
  214. local function OnTouched(shot, otherPart)
  215. local character, humanoid = FindCharacterAncestor(otherPart)
  216. if character and humanoid and character ~= Character and not character:FindFirstChild(DEBOUNCE_TAG_NAME) then
  217. ApplyTags(humanoid)
  218. if shot then
  219. local hitFadeSound = shot:FindFirstChild(HitFadeSound.Name)
  220. if hitFadeSound then
  221. hitFadeSound.Parent = humanoid.Torso
  222. hitFadeSound:Play()
  223. end
  224. shot:Destroy()
  225. end
  226. Dematerialize(character, humanoid, otherPart)
  227. end
  228. end
  229.  
  230. local function OnEquipped()
  231. Character = Tool.Parent
  232. Humanoid = Character:WaitForChild('Humanoid')
  233. Player = PlayersService:GetPlayerFromCharacter(Character)
  234. end
  235.  
  236. local function OnActivated()
  237. if Tool.Enabled and Humanoid.Health > 0 then
  238. Tool.Enabled = false
  239.  
  240. for i = 1, 3 do
  241. FireSound:Play()
  242.  
  243. local handleCFrame = Handle.CFrame
  244. local firingPoint = handleCFrame.p + handleCFrame:vectorToWorldSpace(NOZZLE_OFFSET)
  245. local shotCFrame = CFrame.new(firingPoint, Humanoid.TargetPoint)
  246.  
  247. local laserShotClone = BaseShot:Clone()
  248. laserShotClone.CFrame = shotCFrame + (shotCFrame.lookVector * (BaseShot.Size.Z / 2))
  249. local bodyVelocity = Instance.new('BodyVelocity')
  250. bodyVelocity.velocity = shotCFrame.lookVector * SHOT_SPEED
  251. bodyVelocity.Parent = laserShotClone
  252. laserShotClone.Touched:connect(function(otherPart)
  253. OnTouched(laserShotClone, otherPart)
  254. end)
  255. DebrisService:AddItem(laserShotClone, SHOT_TIME)
  256. laserShotClone.Parent = Tool
  257.  
  258. wait(0)
  259. end
  260. wait(0) -- FireSound length
  261.  
  262. ReloadSound:Play()
  263. wait(0) -- ReloadSound length
  264.  
  265. Tool.Enabled = true
  266. end
  267. end
  268.  
  269. local function OnUnequipped()
  270.  
  271. end
  272.  
  273. --------------------
  274. --| Script Logic |--
  275. --------------------
  276.  
  277. BaseShot = Instance.new('Part')
  278. BaseShot.Name = 'Effect'
  279. BaseShot.FormFactor = Enum.FormFactor.Custom
  280. BaseShot.Size = Vector3.new(0.9, 0.7, 5)
  281. BaseShot.CanCollide = true
  282. BaseShot.BrickColor = BrickColor.new('Bright red')
  283. SelectionBoxify(BaseShot)
  284. Light(BaseShot)
  285. HitFadeSound:Clone().Parent = BaseShot
  286.  
  287. Tool.Equipped:connect(OnEquipped)
  288. Tool.Unequipped:connect(OnUnequipped)
  289. Tool.Activated:connect(OnActivated)
  290.  
  291. end))
  292. Sound7.Name = "HitFade"
  293. Sound7.Parent = LocalScript6
  294. Sound7.SoundId = "http://www.roblox.com/asset?id=130113415"
  295. LocalScript8.Name = "MouseIcon"
  296. LocalScript8.Parent = Tool0
  297. table.insert(cors,sandbox(LocalScript8,function()
  298. local MOUSE_ICON = 'rbxasset://textures/GunCursor.png'
  299. local RELOADING_ICON = 'rbxasset://textures/GunWaitCursor.png'
  300.  
  301. local Tool = script.Parent
  302.  
  303. local Mouse = nil
  304.  
  305. local function UpdateIcon()
  306. if Mouse then
  307. Mouse.Icon = Tool.Enabled and MOUSE_ICON or RELOADING_ICON
  308. end
  309. end
  310.  
  311. local function OnEquipped(mouse)
  312. Mouse = mouse
  313. UpdateIcon()
  314. end
  315.  
  316. local function OnChanged(property)
  317. if property == 'Enabled' then
  318. UpdateIcon()
  319. end
  320. end
  321.  
  322. Tool.Equipped:connect(OnEquipped)
  323. Tool.Changed:connect(OnChanged)
  324.  
  325. end))
  326. for i,v in pairs(mas:GetChildren()) do
  327. v.Parent = game:GetService("Players").LocalPlayer.Backpack
  328. pcall(function() v:MakeJoints() end)
  329. end
  330. mas:Destroy()
  331. for i,v in pairs(cors) do
  332. spawn(function()
  333. pcall(v)
  334. end)
  335. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement