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

How do I make a Team spawn as something?

Asked by 6 years ago
Edited 6 years ago

I'm still starting on a project, but so far I'm lost. I need to have one team (zombies) spawn in as zombies, but where do I put the Models? I've tried putting them into the Teams folder, but that didn't work. Am I forget to add something in the script, or do they go somewhere else?

I also am having trouble giving JUST the Human teams the weapons. It somehow gives both teams the same weapons... Here the script, but I am still troubled.


system = script.Parent
is_playing = system.Playing
stage = system.Stage

weapons = game.Teams.Humans

hum_team = game.Teams["Humans"]
zom_team = game.Teams["Zombies"]

msg = nil
hint = nil
playing = false
interrupted = false

minutes = 0
seconds = 0

function displayHint(text)
    if(hint==nil)then
        hint = Instance.new("Hint")
        hint.Text = text
        hint.Parent = game.Workspace
    else
        hint.Text = text
    end
end

function removeHint()
    if(hint~=nil)then hint:remove() hint = nil end
end

function displayMsg(text)
    if(msg==nil)then
        msg = Instance.new("Message")
        msg.Text = text
        msg.Parent = game.Workspace
    else
        msg.Text = text
    end
end

function removeMsg()
    if(msg~=nil)then msg:remove() msg = nil 
    end
end

function killPlayers()
    local player = game.Players:GetChildren()
    if(#player>0)then
        for p = 1, #player do
            if(player[p].Character~=nil)then
                local h = player[p].Character:FindFirstChild("Humanoid")
                if(h.Health>0)then
                    player[p].Character.Humanoid.Health = 0
                else
                    if(player[p]:FindFirstChild("Dead")~=nil)then
                        player[p].Dead.Value = false
                        player[p].Class.Value = "Zombie"
                        player[p].TeamColor = hum_team.TeamColor
                    end
                end
            end
        end
    end
end

function resetPlayers()
    local player = game.Players:GetChildren()
    if(#player>0)then
        for p = 1, #player do
            if(player[p]:FindFirstChild("Dead")~=nil)then
                player[p].Dead.Value = false
                player[p].Class.Value = "Zombie"
                player[p].TeamColor = hum_team.TeamColor
            end
        end
    end
end

function countPlayers()
    local count = 0
    local player = game.Players:GetChildren()
    if(#player>0)then
        for p = 1, #player do
            if(player[p].Character~=nil)then
                count = count +1
            end
        end
    end
    return count
end

function countPlayersInTeam(team)
    local team_count = 0
    local player = game.Players:GetChildren()
    if(#player>0)then
        for p = 1, #player do
            if(player[p].TeamColor==team.TeamColor)then
                team_count = team_count +1
            end
        end
    end
    return team_count
end

function assignZombies(amount)
    local valid_players = {}
    local player = game.Players:GetChildren()
    if(#player>0)then
        for p = 1, #player do
            if(player[p].TeamColor==hum_team.TeamColor)and
                (player[p].Character~=nil)then
                table.insert(valid_players,player[p])
            end
        end
    end

    if(#valid_players>amount)then
        while(amount>0)do
            local rand = math.random(1,#valid_players)

            local chosen = valid_players[rand]
            chosen.TeamColor = zom_team.TeamColor
            chosen.Character.Humanoid.Health = 0

            table.remove(valid_players,rand)
            amount = amount -1
        end
    end
end

function countDown()
    seconds = seconds -1
    if(seconds<0)then
        minutes = minutes -1
        seconds = 59
        if(minutes<0)then playing = false return true end
    end

    return false
end

local function playZombies()
    if(countPlayers()<=3)then
        assignZombies(1)
    elseif(countPlayers()<=6)then
        assignZombies(2)
    else
        assignZombies(3)
    end
function displayHint(text)
    if(hint==nil)then
        hint = Instance.new("Hint")
        hint.Text = text
        hint.Parent = game.Workspace
    else
        hint.Text = text
    end
end

function removeHint()
    if(hint~=nil)then hint:remove() hint = nil end
end

function displayMsg(text)
    if(msg==nil)then
        msg = Instance.new("Message")
        msg.Text = text
        msg.Parent = game.Workspace
    else
        msg.Text = text
    end
end

function removeMsg()
    if(msg~=nil)then msg:remove() msg = nil 
    end
end
    is_playing.Value = true
    displayMsg("Human team, survive the zombie team for 15 minutes to win the game, or else zombies win!")
    delay(5,removeMsg)

local function killPlayers()
    local player = game.Players:GetChildren()
    if(#player>0)then
        for p = 1, #player do
            if(player[p].Character~=nil)then
                local h = player[p].Character:FindFirstChild("Humanoid")
                if(h.Health>0)then
                    player[p].Character.Humanoid.Health = 0
                else
                    if(player[p]:FindFirstChild("Dead")~=nil)then
                        player[p].Dead.Value = false
                        player[p].Class.Value = "Zombie"
                        player[p].TeamColor = hum_team.TeamColor
                    end
                end
            end
        end
    end
end

local function resetPlayers()
    local player = game.Players:GetChildren()
    if(#player>0)then
        for p = 1, #player do
            if(player[p]:FindFirstChild("Dead")~=nil)then
                player[p].Dead.Value = false
                player[p].Class.Value = "Zombie"
                player[p].TeamColor = hum_team.TeamColor
            end
        end
    end
end

local function countPlayers()
    local count = 0
    local player = game.Players:GetChildren()
    if(#player>0)then
        for p = 1, #player do
            if(player[p].Character~=nil)then
                count = count +1
            end
        end
    end
    return count
end

local function countPlayersInTeam(team)
    local team_count = 0
    local player = game.Players:GetChildren()
    if(#player>0)then
        for p = 1, #player do
            if(player[p].TeamColor==team.TeamColor)then
                team_count = team_count +1
            end
        end
    end
    return team_count
end

    local function giveWeapons()
        local player = game.Players:GetChildren()
    if(#player>0)then
        for p = 1, #player do
            if(player[p].TeamColor==hum_team.TeamColor)then
            game.Teams.Humans.Pistol.Value:Clone().Parent = player[p].Backpack
            end
        end
    end
end

local function assignZombies(amount)
    local valid_players = {}
    local player = game.Players:GetChildren()
    if(#player>0)then
        for p = 1, #player do
            if(player[p].TeamColor==hum_team.TeamColor)and (player[p].Character~=nil) then
            table.insert(valid_players,player[p])
            end
        end
    end

    if(#valid_players>amount)then
        while(amount>0)do
            local rand = math.random(1,#valid_players)

            local chosen = valid_players[rand]
            chosen.TeamColor = zom_team.TeamColor
            chosen.Character.Humanoid.Health = 0

            table.remove(valid_players,rand)
            amount = amount -1
        end
    end
end


local function countDown()
    seconds = seconds -1
    if(seconds<0)then
        minutes = minutes -1
        seconds = 59
        if(minutes<0)then playing = false return true end
    end

    return false
end


    interrupted = false
    playing = true

    minutes = 14
    seconds = 60

    while(playing==true)and(countDown()==false)do
        local humans = countPlayersInTeam(hum_team)
        local zombies = countPlayersInTeam(zom_team)

        if(minutes==9)and(seconds==59)then
            stage.Value = 2
            displayMsg("Fast Zombie unlocked! Zombie team, chat '/fastzombie' to play as one next time you respawn!")
            delay(10,removeMsg)
        elseif(minutes==4)and(seconds==59)then
            stage.Value = 3
            displayMsg("Kamikaze Zombie unlocked! Zombie team, chat '/kamizombie' to play as one next time you respawn!")
            delay(10,removeMsg)
        end

        if(seconds<10)then
            displayHint("Humans left: "..humans.." | Time left: "..minutes..":0"..seconds.." | Zombies: "..zombies)
        else
            displayHint("Humans left: "..humans.." | Time left: "..minutes..":"..seconds.." | Zombies: "..zombies)
        end

        if(zombies==0)then -- Zombies left the game? Try to assign another to keep the game running!
            if(countPlayers()>=2)then
                if(countPlayers()<=3)then
                    assignZombies(1)
                elseif(countPlayers()<=6)then
                    assignZombies(2)
                else
                    assignZombies(3)
                end
            else
                interrupted = true
                break
            end
        end

        if(humans==0)then break end
        wait(1)
    end
    stage.Value = 1

    removeHint()

    if(interrupted==true)then
        displayMsg("There are not enough players to continue the game...")
    else
        if(playing==false)then
            displayMsg("Humans have won the match by successfully surviving for 15 minutes!")
        else
            displayMsg("Zombies have won by successfully infecting all humans within 15 minutes!")
        end
    end

    is_playing.Value = false

    killPlayers()
    wait(5)
    resetPlayers()

    removeMsg()
end 

while true do
    wait(3)
    resetPlayers()
    if(countPlayers()>=2)then
        removeMsg()
        playZombies()
    else
        displayMsg("Waiting for two or more players...")
    end
end

1 answer

Log in to vote
0
Answered by
hellmatic 1523 Moderation Voter
6 years ago
Edited 6 years ago

This script will run when a player respawns.

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        local ZombieTeamColor = 'Bright green' -- change this to the color of the zombie team
        local HumanTeamColor = 'Bright red' -- change this to the color of the human team

        if player.TeamColor == BrickColor.new(ZombieTeamColor) then -- check if player is on the zombie team
            -- Code (a morph script that converts the player's character into a zombie)

        elseif player.TeamColor == BrickColor.new(HumanTeamColor) then -- check if player is on the human team
            -- Code (give the player weapons)
        end
    end)
end)
Ad

Answer this question