Team is not a valid member of Humanoid

I am trying to check if 2 players are on different teams.
Here is my code:

local function _defaultGetTeamCallback(player)
	return player.Team -- Line 485

function WeaponsSystem.getTeam(player)
	local handler = _defaultGetTeamCallback
	return handler(player)

function WeaponsSystem.playersOnDifferentTeams(player1, player2)
	if player1 == player2 or player1 == nil or player2 == nil then
		-- This allows players to damage themselves and NPC's
		return true
	local player1Team = WeaponsSystem.getTeam(player1)
	local player2Team = WeaponsSystem.getTeam(player2)
	--print(player1Team .. " " .. player2Team .. " " .. player1Team~=player2Team)
	print(player1Team) -- Line 505
	print(player2Team) -- Line 506
	if player1Team ~= player2Team then return true end

Whenever my function WeaponsSystem.playersOnDifferentTeams is called, I get this output from the console:

Line 505 and 506 are the print statements for player1Team and player2Team, which are supposedly determined by _defaultGetTeamCallback. How is it possible that I am getting the value of the teams from the callback on line 485 if the callback isn’t working?

How can I correctly make the comparison between two teams and return true or false?

The issue is that you are inputting a humanoid into the function and not the player, you can resolve it by getting the model through the humanoids parent, then using get player from character function to get the player Players | Roblox Creator Documentation.

1 Like

I solved this by passing in the humanoid to the function this way:

if WeaponsSystem.playersOnDifferentTeams(dealer, Players:GetPlayerFromCharacter(target.Parent))

I was trying to figure this out for a long time, thank you!