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