Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.02 KB | None | 0 0
  1. -- Objects
  2.  
  3. Player = game.Players.LocalPlayer
  4. Gun = Instance.new("Tool")
  5. Handle = Instance.new("Part")
  6. Fire = Instance.new("Sound")
  7. Reload = Instance.new("Sound")
  8. LightX = Instance.new("PointLight")
  9. HitFade = Instance.new("Sound")
  10. Mesh = Instance.new("SpecialMesh")
  11.  
  12. -- Assets
  13.  
  14. game.ContentProvider:Preload("rbxassetid://130099641")
  15. game.ContentProvider:Preload("rbxassetid://130093033")
  16. game.ContentProvider:Preload("rbxassetid://130113322")
  17. game.ContentProvider:Preload("rbxassetid://130113370")
  18. game.ContentProvider:Preload("rbxassetid://139121396")
  19. game.ContentProvider:Preload("rbxassetid://130113370")
  20.  
  21. -- Properties
  22.  
  23. Gun.Parent = Player.Backpack
  24. Gun.Name = ("Gun")
  25. Gun.ToolTip = ("rekt players")
  26. Gun.TextureId = ("rbxassetid://130093050")
  27. Gun.GripForward = Vector3.new(0, 0, -1)
  28. Gun.GripPos = Vector3.new(0, -0.1, 0.75)
  29. Gun.GripRight = Vector3.new(1, 0, 0)
  30. Gun.GripUp = Vector3.new(0, 1, 0)
  31.  
  32. Handle.Parent = Gun
  33. Handle.Name = ("Handle")
  34.  
  35. Fire.Volume = (1)
  36. Fire.SoundId = ("rbxassetid://130113322")
  37. Fire.Parent = Handle
  38. Fire.Name = ("Fire")
  39.  
  40. Reload.Volume = (1)
  41. Reload.SoundId = ("rbxassetid://130113370")
  42. Reload.Parent = Handle
  43. Reload.Name = ("Reload")
  44.  
  45. Mesh.Name = ("Mesh")
  46. Mesh.Parent = Handle
  47. Mesh.MeshId = ("rbxassetid://130099641")
  48. Mesh.TextureId = ("rbxassetid://130093033")
  49. Mesh.Scale = Vector3.new(0.65, 0.65, 0.65)
  50.  
  51. LightX.Name = ("PointLight")
  52. LightX.Parent = Handle
  53. LightX.Color = Color3.new(0, 0, 1)
  54. LightX.Range = (6)
  55. LightX.Brightness = (1)
  56. LightX.Enabled = true
  57.  
  58. HitFade.Name = ("HitFade")
  59. HitFade.Parent = Handle
  60. HitFade.Volume = (1)
  61.  
  62. -- Copied from the original tool
  63.  
  64. -----------------
  65. --| Constants |--
  66. -----------------
  67.  
  68. local SHOT_SPEED = 100
  69. local SHOT_TIME = 1
  70.  
  71. local NOZZLE_OFFSET = Vector3.new(0, 0.4, -1.1)
  72.  
  73. -----------------
  74. --| Variables |--
  75. -----------------
  76.  
  77. local PlayersService = game:GetService('Players')
  78. local DebrisService = game:GetService('Debris')
  79.  
  80. local Tool = Gun
  81.  
  82. local Character = nil
  83. local Humanoid = nil
  84. local Player = nil
  85.  
  86. local BaseShot = nil
  87.  
  88. -----------------
  89. --| Functions |--
  90. -----------------
  91.  
  92. -- Returns a character ancestor and its Humanoid, or nil
  93. local function FindCharacterAncestor(subject)
  94. if subject and subject ~= workspace then
  95. local humanoid = subject:FindFirstChild('Humanoid')
  96. if humanoid then
  97. return subject, humanoid
  98. else
  99. return FindCharacterAncestor(subject.Parent)
  100. end
  101. end
  102. return nil
  103. end
  104.  
  105. -- Removes any old creator tags and applies new ones to the specified target
  106. local function ApplyTags(target)
  107. while target:FindFirstChild('creator') do
  108. target.creator:Destroy()
  109. end
  110.  
  111. local creatorTag = Instance.new('ObjectValue')
  112. creatorTag.Value = Player
  113. creatorTag.Name = 'creator' --NOTE: Must be called 'creator' for website stats
  114.  
  115. local iconTag = Instance.new('StringValue')
  116. iconTag.Value = Tool.TextureId
  117. iconTag.Name = 'icon'
  118.  
  119. iconTag.Parent = creatorTag
  120. creatorTag.Parent = target
  121. DebrisService:AddItem(creatorTag, 4)
  122. end
  123.  
  124. -- Returns all objects under instance with Transparency
  125. local function GetTransparentsRecursive(instance, partsTable)
  126. local partsTable = partsTable or {}
  127. for _, child in pairs(instance:GetChildren()) do
  128. if child:IsA('BasePart') or child:IsA('Decal') then
  129. table.insert(partsTable, child)
  130. end
  131. GetTransparentsRecursive(child, partsTable)
  132. end
  133. return partsTable
  134. end
  135.  
  136. local function SelectionBoxify(instance)
  137. local selectionBox = Instance.new('SelectionBox')
  138. selectionBox.Adornee = instance
  139. selectionBox.Color = BrickColor.new('Toothpaste')
  140. selectionBox.Parent = instance
  141. return selectionBox
  142. end
  143.  
  144. local function Light(instance)
  145. local light = LightX:Clone()
  146. light.Range = light.Range + 2
  147. light.Parent = instance
  148. end
  149.  
  150. local function FadeOutObjects(objectsWithTransparency, fadeIncrement)
  151. repeat
  152. local lastObject = nil
  153. for _, object in pairs(objectsWithTransparency) do
  154. object.Transparency = object.Transparency + fadeIncrement
  155. lastObject = object
  156. end
  157. wait()
  158. until lastObject.Transparency >= 1 or not lastObject
  159. end
  160.  
  161. local function Dematerialize(character, humanoid, firstPart)
  162. humanoid.WalkSpeed = 0
  163.  
  164. local parts = {}
  165. for _, child in pairs(character:GetChildren()) do
  166. if child:IsA('BasePart') then
  167. child.Anchored = true
  168. table.insert(parts, child)
  169. elseif child:IsA('LocalScript') or child:IsA('Script') then
  170. child:Destroy()
  171. end
  172. end
  173.  
  174. local selectionBoxes = {}
  175.  
  176. local firstSelectionBox = SelectionBoxify(firstPart)
  177. Light(firstPart)
  178. wait(0.05)
  179.  
  180. for _, part in pairs(parts) do
  181. if part ~= firstPart then
  182. table.insert(selectionBoxes, SelectionBoxify(part))
  183. Light(part)
  184. end
  185. end
  186.  
  187. local objectsWithTransparency = GetTransparentsRecursive(character)
  188. FadeOutObjects(objectsWithTransparency, 0.1)
  189.  
  190. wait(0.5)
  191.  
  192. humanoid.Health = 0
  193. DebrisService:AddItem(character, 2)
  194.  
  195. local fadeIncrement = 0.05
  196. Delay(0.2, function()
  197. FadeOutObjects({firstSelectionBox}, fadeIncrement)
  198. if character then
  199. character:Destroy()
  200. end
  201. end)
  202. FadeOutObjects(selectionBoxes, fadeIncrement)
  203. end
  204.  
  205. local function OnTouched(shot, otherPart)
  206. local character, humanoid = FindCharacterAncestor(otherPart)
  207. if character and humanoid and character ~= Character then
  208. ApplyTags(humanoid)
  209. if shot then
  210. local HitFade = shot:FindFirstChild(HitFade.Name)
  211. if HitFade then
  212. HitFade.Parent = humanoid.Torso
  213. HitFade:Play()
  214. end
  215. shot:Destroy()
  216. end
  217. Dematerialize(character, humanoid, otherPart)
  218. end
  219. end
  220.  
  221. local function OnEquipped()
  222. Character = Tool.Parent
  223. Humanoid = Character:WaitForChild('Humanoid')
  224. Player = PlayersService:GetPlayerFromCharacter(Character)
  225. end
  226.  
  227. local function OnActivated()
  228. if Tool.Enabled and Humanoid.Health > 0 then
  229. Tool.Enabled = false
  230.  
  231. Fire:Play()
  232.  
  233. local handleCFrame = Handle.CFrame
  234. local firingPoint = handleCFrame.p + handleCFrame:vectorToWorldSpace(NOZZLE_OFFSET)
  235. local shotCFrame = CFrame.new(firingPoint, Humanoid.TargetPoint)
  236.  
  237. local laserShotClone = BaseShot:Clone()
  238. laserShotClone.CFrame = shotCFrame + (shotCFrame.lookVector * (BaseShot.Size.Z / 2))
  239. local bodyVelocity = Instance.new('BodyVelocity')
  240. bodyVelocity.velocity = shotCFrame.lookVector * SHOT_SPEED
  241. bodyVelocity.Parent = laserShotClone
  242. laserShotClone.Touched:connect(function(otherPart)
  243. OnTouched(laserShotClone, otherPart)
  244. end)
  245. DebrisService:AddItem(laserShotClone, SHOT_TIME)
  246. laserShotClone.Parent = Tool
  247.  
  248. -- FireSound length
  249.  
  250. Reload:Play()
  251. -- ReloadSound length
  252.  
  253. Tool.Enabled = true
  254. end
  255. end
  256.  
  257. local function OnUnequipped()
  258.  
  259. end
  260.  
  261. --------------------
  262. --| Script Logic |--
  263. --------------------
  264.  
  265. BaseShot = Instance.new('Part')
  266. BaseShot.Name = 'Effect'
  267. BaseShot.FormFactor = Enum.FormFactor.Custom
  268. BaseShot.Size = Vector3.new(0.2, 0.2, 3)
  269. BaseShot.CanCollide = false
  270. BaseShot.BrickColor = BrickColor.new('Toothpaste')
  271. SelectionBoxify(BaseShot)
  272. Light(BaseShot)
  273. HitFade:Clone().Parent = BaseShot
  274.  
  275. Tool.Equipped:connect(OnEquipped)
  276. Tool.Unequipped:connect(OnUnequipped)
  277. Tool.Activated:connect(OnActivated)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement