Code Not Working Upon Changing Team?

Im Making a Door that only unlocks when you are on the police team but when i change team it stops working

local TweenSer = game:GetService("TweenService")
script.Parent.OpenLeftHitbox.Touched:Connect(function(hit)
	if hit.Name == "HumanoidRootPart" and open == false then
		open = true
		local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
		if plr then
		if plr.TeamColor == BrickColor.new("Bright blue") then
		local tweenInfo = TweenInfo.new(0.4, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut,0,false,0)
		local openL = TweenSer:Create(script.Parent.LeftDoor.Main, tweenInfo, {CFrame = script.Parent.LOLCFrame.CFrame})
		openL:Play()

		openL.Completed:Connect(function()
			wait(0.3)
			TweenSer:Create(script.Parent.LeftDoor.Main, tweenInfo, {CFrame = script.Parent.LeftMain.CFrame}):Play()			
			wait(0.8)
			open = false 
				end)
			end
		end
	end
end)


script.Parent.OpenRightHitbox.Touched:Connect(function(hit)
	if hit.Name == "HumanoidRootPart" and open == false then
		open = true
		local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
		if plr then
			if plr.TeamColor == BrickColor.new("Bright blue") then
		local tweenInfo = TweenInfo.new(0.4, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut,0,false,0)
		local openL = TweenSer:Create(script.Parent.LeftDoor.Main, tweenInfo, {CFrame = script.Parent.LORCFrame.CFrame})
		openL:Play()
		openL.Completed:Connect(function()
			wait(0.3)
			TweenSer:Create(script.Parent.LeftDoor.Main, tweenInfo, {CFrame = script.Parent.LeftMain.CFrame}):Play()			
			wait(0.8)
			open = false 
				end)
			end
		end
	end
end)```


Changing Team 
```game.ReplicatedStorage.Events.TeamChange.OnServerEvent:Connect(function(player, TeamColor)
	player.TeamColor = TeamColor
	for i,v in pairs(player.Backpack:GetChildren()) do
		v:Destroy()
	end
end)

Can you elaborate on what you mean by “it stops working”?

the door doesnt tween thats what i mean

That would be because your script checks the player team before tweening:

if plr.TeamColor == BrickColor.new(“Bright blue”) then

yeah otherwise it would open the door when u are a prisoner

Yes, so how is it broken? You said it did not open once you change teams which sounds like it is doing exactly what you want.

when i change to prisoner activate the door and change back to police it stops working

Just did some testing and realised that you are setting the debounce “open” to true regardless of whether the player is on the police team. This means it sets “open” to true if a non-police player touches the door which is never set back to false.

To fix this, simply put open = true under:

if plr.TeamColor == BrickColor.new(“Bright blue”) then

2 Likes