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