isEquipped is not a valid member of Mouse "Instance"

function Action.new(tool: Tool)
	local data = modules.Data.Tools:FindFirstChild(tool.Name)

	if not data then
		warn(`Could not find valid data for tool: {tool.Name}`)
		return
	end

	local self = setmetatable({
		_Maid = Maid.new(),
		_tool = tool,
		_data = require(data),
		_isEquipped = false,
	}, Action)

	self:_init()

	return self
end

function Action:_init()
	self._Maid:GiveTask(self._tool.Equipped:Connect(self._onEquipped))
	self._Maid:GiveTask(self._tool.Unequipped:Connect(self._onUnequipped))
end

function Action:_onEquipped(mouse: Mouse)
	if self._isEquipped then  -- Errors on this line?
		return
	end
	self._isEquipped = true
	print("Equipped")
end

Not sure what I am doing wrong here? Maybe a spelling error or something?

_isEquipped is not a valid member of Mouse "Instance"

Colon syntax makes self the implicit first parameter. When dot notation is used, the object must be passed explicitly. So when the event calls the function, it’s attempting to pass the mouse as the object. You can fix this by wrapping the call in another function.

function Action:_init()
	self._Maid:GiveTask(self._tool.Equipped:Connect(function(mouse)
		self:_onEquipped(mouse)
	end)
	self._Maid:GiveTask(self._tool.Unequipped:Connect(function()
		self:_onUnequipped()
	end)
end

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.