Team only door not working

Hi, i’ve been trying to fix this door but nothing has worked so far, the door is supposed to kill anyone who is not inside the security team, but it kills everyone who touches it instead, even if you are in the security team, there are no errors in the output and I don’t know what’s wrong with this script. Could someone help me?

local team1 = game.Teams.Security
local door = script.Parent

door.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if plr.Team == team1 then
			script.Parent.Laser:Play()
		else
			script.Parent.Laser:Play()
			humanoid.Health = 0
		end
	end
end)

Maybe try making plr.Team, plr.Team.Color and after it team1.Color

Are you changing player’s team through a local script? if so that’s your issue. Server can not see the changes from client. You should use remote events to change the team if you’re using a local script to change team.

They arent changing the team, they are checking the team. They can do that.

Well, the team is changed through a GUI that works with a Local Script, so I think this is the problem.

That is. But, you never mentioned you were changing teams at all.

Yeah that’s the issue. When you change the team on a local script server won’t see it so it’s killing you because server says “you’re not in Security team”. If you use a remote event to change team you will fix it. Hope this makes sense.

It is the problem. Change the script to a ServerScript, as if you change it on the client, only the client sees it, and you check the team on the Server, which the server doesn’t see that the team is actually security.