Sword Script Team Kill not working

I have a sword script, however, there’s a section where if the player has the same TeamColor as the player they are trying to kill, no damage is taken.

However, despite both players being on the same team, the target still takes damage if they are on the same TeamColor as the hitter. Any insight on this would be appreciated.

local tool = script.Parent
local damage = script.Parent.Damage.Value
local Debris = game:GetService("Debris") 

local function TagHumanoid(humanoid, player)
	local Creator_Tag = Instance.new("ObjectValue")
	Creator_Tag.Name = "creator"
	Creator_Tag.Value = player
	Debris:AddItem(Creator_Tag, 2)
	Creator_Tag.Parent = humanoid
end

local function UntagHumanoid(humanoid)
	for i, v in pairs(humanoid:GetChildren()) do
		if v:IsA("ObjectValue") and v.Name == "creator" then
			v:Destroy()
		end
	end
end

local function onTouch(partOther)
	local humanOther = partOther.Parent:FindFirstChild("Humanoid")
	local player = tool.Parent

	if not humanOther then return end

	TagHumanoid(humanOther, player)

	local playerTeam = player:FindFirstChild("TeamColor")
	local otherPlayerTeam = partOther.Parent:FindFirstChild("TeamColor")

	if playerTeam and otherPlayerTeam == otherPlayerTeam then 
		print("same team")
	else
		humanOther:TakeDamage(damage)
	end

end

local function slash()
	local str = Instance.new("StringValue")
	str.Name = "toolanim"
	str.Value = "Slash"
	str.Parent = tool
end

tool.Activated:Connect(slash)
tool.Handle.Touched:Connect(onTouch)

Wouldn’t it be

if playerTeam == otherPlayerTeam?

You’re also checking if otherPlayerTeam is otherPlayerTeam? I don’t think that’s necessary

Yeah, I caught onto this a few minutes after. I changed the script to if playerTeam == otherPlayerTeam and now it seems like no damage is dealt at all. Even if they’re on opposing teams. I also added some debug but that doesn’t print either?

This might not be related, but in the script you connect the touched (damage event), so can’t the sword just damage a player at all times without the need to swing it?

Yep, that’s an intended functionality though

Could this be because the sword is maybe hitting an accessory? In that case partOther.Parent:FindFirstChild(“Humanoid”) wouldn’t work. Did you try printing the hit object?

I doubt it since the sword was dealing damage fine before but I’ll debug that now and let you know