local v=require((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\078\101\118\101\114\109\111\114\101"))local m=v("\077\097\105\100")local u=v("\067\104\097\114\097\099\116\101\114\085\116\105\108")local q=v("\086\097\108\117\101\079\098\106\101\099\116")local d={}d.ClassName="\069\113\117\105\112\112\101\100\084\114\097\099\107\101\114"d.__index=d function d.new(v)local u=setmetatable({},d)assert(v and v:IsA("\084\111\111\108"))u._tool=v u._maid=m.new()u.Player=q.new()u._maid:GiveTask(u.Player)u._maid:GiveTask(u._tool.Equipped:Connect(function()u:_update()end))u._maid:GiveTask(u._tool.Unequipped:Connect(function()u:_update()end))u:_update()return u end function d._update(v)local m=u.GetPlayerFromCharacter(v._tool)if not m then v._maid._diedConn=nil v.Player.Value=nil return end local q=u.GetAlivePlayerHumanoid(m)if not q then v._maid._diedConn=nil v.Player.Value=nil return end v.Player.Value=m v._maid._diedConn=q.Died:Connect(function()v:_update()end)end function d.Destroy(v)v._maid:DoCleaning()setmetatable(v,nil)end return d
--- Tracks the equipped player of a tool
-- @classmod EquippedTracker

local require = require(game:GetService("ReplicatedStorage"):WaitForChild("Nevermore"))

local Maid = require("Maid")
local CharacterUtil = require("CharacterUtil")
local ValueObject = require("ValueObject")

local EquippedTracker = {}
EquippedTracker.ClassName = "EquippedTracker"
EquippedTracker.__index = EquippedTracker

function EquippedTracker.new(tool)
	local self = setmetatable({}, EquippedTracker)

	assert(tool and tool:IsA("Tool"))
	self._tool = tool

	self._maid = Maid.new()

	-- Tracks current equipped player who has an alive humanoid
	self.Player = ValueObject.new()
	self._maid:GiveTask(self.Player)

	self._maid:GiveTask(self._tool.Equipped:Connect(function()
		self:_update()
	end))
	self._maid:GiveTask(self._tool.Unequipped:Connect(function()
		self:_update()
	end))
	self:_update()

	return self
end

function EquippedTracker:_update()
	local player = CharacterUtil.GetPlayerFromCharacter(self._tool)
	if not player then
		self._maid._diedConn = nil
		self.Player.Value = nil
		return
	end

	local humanoid = CharacterUtil.GetAlivePlayerHumanoid(player)
	if not humanoid then
		self._maid._diedConn = nil
		self.Player.Value = nil
		return
	end

	self.Player.Value = player
	self._maid._diedConn = humanoid.Died:Connect(function()
		self:_update()
	end)
end

function EquippedTracker:Destroy()
	self._maid:DoCleaning()
	setmetatable(self, nil)
end

return EquippedTracker