CanCollide not disabling

Hello, the title explains it all.
Code:


local Players = game:GetService("Players")
local TouchPart = script.Parent

TouchPart.Touched:Connect(function(touched)
	if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
		local Player = Players:GetPlayerFromCharacter(touched.Parent)
		if Player then
			if Player.Team == "Red" then
				TouchPart.CanCollide = false
				wait(0.5)
				TouchPart.CanCollide = true
			end
		end
	end
end)

There are no errors or warning in output
Very sorry if there is a big lack of information.

Player.Team is a Team object, not a string, so it is marked as false, change it to this

local Players = game:GetService("Players")
local TouchPart = script.Parent
local TeamTarget = game:GetService("Teams"):FindFirstChild("Red")

TouchPart.Touched:Connect(function(touched)
	if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
		local Player = Players:GetPlayerFromCharacter(touched.Parent)
		if Player and Player.Team == TeamTarget then
			TouchPart.CanCollide = false
			task.wait(0.5)
			TouchPart.CanCollide = true
		end
	end
end)