Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-2

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

Asked by 8 years ago

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

Log in to vote
0
Answered by
dyler3 1510 Moderation Voter
8 years ago

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

0
Seems like a good script :D Ill test it out and post the results CarterTheHippo 120 — 8y
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. dyler3 1510 — 8y
0
Yea i tested it and it didnt work ill check with the new one though :p CarterTheHippo 120 — 8y
0
IT WORKS! Yes! Thank you so much I am very grateful! CarterTheHippo 120 — 8y
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. CarterTheHippo 120 — 8y
Ad

Answer this question