Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

A door that opens when a certain team has no players/dead. Any help?

I am looking for just a basic part, that when there are 0 players on the bright blue team, that part goes away/turns transparency = 1 and cancollide = false or simply is nil

transparency = 1
cancollide = false

or

script.Parent = nil

1 answer

✓ Accepted answer

##Getting the players First, you would need to check how many players there are on that team. To do this, we'll get a table of all the players, then go through and check the teams of all of them:

local BluePlayers=0

function GetAmountOnBlue()
	BluePlayers=0
	local Players=game.Players:GetChildren()
	for _,Player in pairs(Players) do
		if Player.TeamColor==BrickColor.new("Bright blue") then
			BluePlayers=BluePlayers+1
		end
	end
end

while script.Parent do
	GetAmountOnBlue()
end

Now, this would work to constantly update the amount of players on the blue team.


##Opening the door However we still need to change the brick. To do that, we'll add in this bit of code:

if BluePlayers==0 then
	script.Parent.Transparency=1
	script.Parent.CanCollide=false
else
	script.Parent.Transparency=0
	script.Parent.CanCollide=true
end

This would check if there is any players on the 'Bright blue' team, and if there isn't, it will "open" the door.


##Final product Now that that's done, let's put the entire code together:

local BluePlayers=0

function GetAmountOnBlue()
	BluePlayers=0
	local Players=game.Players:GetChildren()
	for _,Player in pairs(Players) do
		if Player.TeamColor==BrickColor.new("Bright blue") then
			BluePlayers=BluePlayers+1
		end
	end
end

while script.Parent do
	wait()
	GetAmountOnBlue()
	if BluePlayers==0 then
		script.Parent.Transparency=1
		script.Parent.CanCollide=false
	else
		script.Parent.Transparency=0
		script.Parent.CanCollide=true
	end
end

So, I believe this should work now how you wanted.


Anyways, if you have any further questions/problems, please leave a comment below. Hope I helped :P

####-Dyler3

5 comments

0

Seems like a good script :D Ill test it out and post the results

0

Eh, I just found a mistake I made in the script. You might need to try it again with the one I just updated.

0

Yea i tested it and it didnt work ill check with the new one though :p

0

IT WORKS! Yes! Thank you so much I am very grateful!

0

I have more questing for this particular game I am trying to put together. Its gettig closer and closer! If you woud like to help out I have other scripting questing I have posted on here.

This discussion is preserved as it was. New answers, comments, and votes are closed.