-----<< 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)
