View difference between Paste ID: AX3AQDa1 and p2yQiLqt
SHOW: | | - or go back to the newest paste.
1
originalAmmo = script.Parent.Ammo.Value
2
m = Instance.new("Message")
3
4
function computeDirection(vec)
5
	local lenSquared = vec.magnitude^2
6
	local invSqrt = 1 / math.sqrt(lenSquared)
7
	return Vector3.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt)
8
end
9
10
11
12
function updateAmmo()
13
	m.Text = " "
14
	--for i = 1,script.Parent.Ammo.Value do
15
	--	m.Text = m.Text .. "|"
16
	--end
17
	--for i = 1, (originalAmmo - script.Parent.Ammo.Value) do
18
	--	m.Text = m.Text .. " "
19
	--end
20
	m.Text = m.Text .. " " .. script.Parent.Ammo.Value.. "/12"
21
end
22
23
24
function fire(v)
25
	for i = 1,1 do
26
		script.Parent.Handle.Fire:play()
27
		script.Parent.Ammo.Value = script.Parent.Ammo.Value - 1
28
		updateAmmo()
29
		local dir = v - script.Parent["Handle"].Position
30
		dir = computeDirection(dir)
31
		local pos = script.Parent["Handle"].Position + (dir * 8)
32
		local p = Instance.new("Part")
33
		p.Name = "Projectile"
34
		p.CFrame = CFrame.new(pos, pos + dir)
35
		p.BrickColor = BrickColor.new(24)
36
		p.Reflectance = 0.1
37
		p.Velocity = (script.Parent.Parent["Head"].Position - v).unit * -150
38
		p.Size = Vector3.new(1, 0.4, 1)
39
		p.formFactor = 2
40
		local mesh = script.Parent.Mesh:clone()
41
		mesh.Parent = p
42
		local upforce = Instance.new("BodyForce")
43
		upforce.force = Vector3.new(0, p:GetMass() * 196, 0)
44
		upforce.Parent = p
45
		local s = script.Parent["ProjectileScript"]:Clone()
46
		s.Disabled = false
47
		s.Parent = p
48
		p.Parent = game.Workspace
49
		wait(0)
50
	end
51
end
52
53
54
function onActivated()
55
	if script.Parent.Enabled == true then
56
		--script.Parent.Enabled = false
57
		if script.Parent.Ammo.Value > 0 then
58
			fire(script.Parent.Parent["Humanoid"].TargetPoint)
59
		else
60
			if script.Parent.Clips.Value >= -30000000000000 then
61
				script.Parent.Enabled = false
62
				script.Parent.Handle.Reload:play()
63
				m.Text = "reloading"
64
				for i =1,5 do
65
					wait(5) --Reload Time
66
					m.Text = m.Text .. "."
67
				end
68
				script.Parent.Clips.Value = script.Parent.Clips.Value - 1
69
				script.Parent.Ammo.Value = originalAmmo
70
				updateAmmo()
71
				script.Parent.Enabled = true
72
			else
73
				m.Text = "No more clips!"
74
			end
75
		end
76
		wait(0.11)
77
		--script.Parent.Enabled = true
78
	end
79
end
80
81
82
function onEquipped()
83-
	local p = game.Players:GetChildren()
83+
	local p = game.Players:Goku888008()
84
	for i = 1,#p do
85
		if p[i].Character == script.Parent.Parent then
86
			m.Parent = p[i]
87
		end
88
	end
89
	updateAmmo()
90
end
91
92
function onUnequipped()
93
	m.Parent = nil
94
end
95
96
97
script.Parent.Activated:connect(onActivated)
98
script.Parent.Equipped:connect(onEquipped)
99
script.Parent.Unequipped:connect(onUnequipped)