reloadEvent.OnServerEvent:Connect(reload)fireEvent.OnServerEvent:Connect(function(z,h)if tool.Parent==z.Character then if currentAmmo<=0 then return reload(z)end if canFire then canFire=false currentAmmo=currentAmmo-1 shotEvent:FireClient(z,currentAmmo,ammoLeft)fireSound:Play()muzzle.EffectAttachment.MuzzleFlash:Emit(1)spawn(function()createBullet(h)end)wait()tool.GripUp=Vector3.new(0,.2,1)wait()tool.GripUp=Vector3.new(0,0,1)delay(attackCooldown,function()canFire=true end)end end end)player.Character.Humanoid.Touched:Connect(function(z)if z.Name=="\065\109\109\111\067\114\097\116\101"and(equipped and ammoLeft<extraAmmo)then tool.Handle.ReplenishSound:Play()ammoLeft=extraAmmo shotEvent:FireClient(player,currentAmmo,ammoLeft)end end)
-----<< CONNECTIONS >>-----

reloadEvent.OnServerEvent:Connect(reload)
fireEvent.OnServerEvent:Connect(function(player, target)
	if tool.Parent == player.Character then
		-- If tool has enough shots then fires. Otherwise reloads.
		if currentAmmo <= 0 then
			return reload(player)
		end
		if canFire then
			canFire = false
			currentAmmo = currentAmmo - 1
			shotEvent:FireClient(player, currentAmmo, ammoLeft)
			fireSound:Play()
			muzzle.EffectAttachment.MuzzleFlash:Emit(1)
			spawn(function()
				createBullet(target)
			end)
			wait()
			tool.GripUp = Vector3.new(0, 0.2, 1)
			wait()
			tool.GripUp = Vector3.new(0, 0, 1)
			delay(attackCooldown, function()
				canFire = true
			end)
		end
	end
end)
player.Character.Humanoid.Touched:Connect(function(obj)
	if obj.Name == "AmmoCrate" and equipped and ammoLeft < extraAmmo then
		tool.Handle.ReplenishSound:Play()
		ammoLeft = extraAmmo
		shotEvent:FireClient(player, currentAmmo, ammoLeft)
	end
end)
