Team door transparancy

Hi everyone. I have a door in my game that I want to be transparent and can collide false IF you are on a certain team. If your not on the team the door is not transparent and the can collide is true.

I am trying to accomplish this by putting a local script in starter player scripts. The script is below but it does not seem to do anything. haha

Anyone have any ideas?

local player = game.Players.LocalPlayer
local Teams = game:GetService("Teams")
local team = Teams["Team1"]

if player.Team == team then
	game.Workspace.worldobjects.team1door.CanCollide = false
	game.Workspace.worldobjects.team1door.Transparency = 1
	
end
``

Script works. Problem will be how you used it.

local player = game.Players.LocalPlayer
local Teams = game:GetService("Teams")
local team = Teams["Team1"]

repeat
wait()
until team ~= nil

print(team)

if player.Team == team then
	game.Workspace.worldobjects.team1door.CanCollide = false
	game.Workspace.worldobjects.team1door.Transparency = 1
	
end

try waiting until the team variable isn’t nil

Can you explain please? This script works with gamepass doors. I dont understand why it doesn’t work with teams.

I tried this and the door is still solid and I cannot pass through it.

When player join and on team is set autoassignable, then script work.

it only works if I drop this local script into team morphs. If I put it in start player scripts it does not work.

local player = game.Players.LocalPlayer
local Teams = game:GetService("Teams")
local team = Teams["Team1"]

while task.wait() do
	if player.Team ~= nil then
		game.Workspace.worldobjects.team1door.CanCollide = false
		game.Workspace.worldobjects.team1door.Transparency = 1
		break
	end
end

1 Like

try this

local player = game.Players.LocalPlayer;
local Teams = game:GetService("Teams");
local team = Teams.Team1;


player:GetPropertyChangedSignal("Team"):Connect(function()
	if player.Team == team then
		game.Workspace.worldobjects.team1door.CanCollide = false;
		game.Workspace.worldobjects.team1door.Transparency = 1;
	end
end)
2 Likes

that actually works, but my idea is flawed. Once you play on team 1 the door remains open forever, even if you switch to team 2 or team 3. How would I make the door not transparent if your not on team 1?

It may be because it’s breaking the while loop once the player’s team is not nil.

You could also try this:

local player = game.Players.LocalPlayer
local Teams = game:GetService("Teams")

player:GetPropertyChangedSignal("Team"):Connect(function()
	for i,v in pairs(game.Teams:GetDescendants()) do
		if player.Team ~= v then
			game.Workspace.worldobjects["team"..i.."door"].CanCollide = true;
			game.Workspace.worldobjects["team"..i.."door"].Transparency = 0;
		else
			game.Workspace.worldobjects["team"..i.."door"].CanCollide = false;
			game.Workspace.worldobjects["team"..i.."door"].Transparency = 1;
		end
	end
end)
3 Likes

How do I define which can can pass through the door. Team 1, 2, or 3?

I think I am going to try something way easier. I’ll make a new post about it tomorrow when I get back on.

Thanks for all the help but this idea is too complicated for what I am trying to accomplish.

actually ill just post my idea before I go to bed. I just made the door kill the other team if they touch it. It works and it is a lot simpler. But it still gives an error.

script.Parent.Touched:Connect(function(hit)
	local character = hit.Parent
	local player = game.Players:GetPlayerFromCharacter(character)
	local Teams = game:GetService("Teams")
	local team = Teams["team1"]	
	 if player.Team ~= team then
		character.Humanoid.Health = 0
	end
end)

The error is on line six. If you pass through the door as team1 the door does not kill you but it does give this error. 04:53:07.088 Workspace.worldobjects.teamdoor.Script:6: attempt to index nil with ‘Team’ - Server - Script:6

Anyone know what this error is from?

try this:

script.Parent.Touched:Connect(function(hit)
	local character = hit.Parent
	local player = game.Players:GetPlayerFromCharacter(character)
	
	if player and player.Team ~= nil then
		if player.Team.Name ~= "team1" then
			character.Humanoid.Health = 0
		end
	end
end)