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

How to pick a team color?

Asked by 10 years ago
players = game.Players:GetChildren()
    randomp = players[math.random(#players)]
    print(randomp.Name .. " is killer")
    game.Player.TeamColor = BrickColor.new("Bright red")
    for i,v in pairs(players)  do
        if v.Name ~= randomp.Name then
            print(v.Name .. " is runner")
            game.Player.TeamColor = BrickColor.new("Bright blue")
        end
    end

How come this won't work? It CANNOT just go and kill the player so they spawn at a certain spawn. I'm making a deathrun recreation, so I need EXACT.

This is the full script:

-- NinjoOnline --

map = game.ServerStorage.Maps:GetChildren()

h = Instance.new("Hint", game.Workspace)

while true do
    if game.Players.NumPlayers > 1 then
        h.Text = "Deciding what map to play"
        wait(5)
        ranMap = math.random(1, #map)
        mapChosen = map[ranMap]
        h.Text = "Map Chosen: " .. mapChosen.Name
        wait(3)
        mapChosenClone = mapChosen:Clone()
        mapChosenClone.Parent = game.Workspace
        wait(1)

-------------------------
-- Picks random killer --
-------------------------

        players = game.Players:GetChildren()
        local randomp = players[math.random(1,#players)]
        print(randomp.Name .. " is killer")
        randomp.TeamColor = BrickColor.new("Bright red")
        randomp:LoadCharacter()
        for i,v in pairs(players)  do
            if v.Name ~= randomp.Name then
                print(v.Name .. " is runner")
                v.TeamColor = BrickColor.new("Bright blue")
                v:LoadCharacter()
            end
        end

---------------------------------
-- Teleport players to the map --
---------------------------------

        rspawn = mapChosenClone.RunnerSpawn:GetChildren()
        kspawn = mapChosenClone.KillerSpawn:GetChildren()

        for i,v in pairs(game.Players:GetChildren()) do
            name = v.Name
            check = game.Workspace:FindFirstChild(name)
            if check then
                checkHumanoid = check:FindFirstChild("Humanoid")
                if checkHumanoid then
                    check:MoveTo(rspawn[i].Position)
                end
            end
        end

---------------------------
-- Game begins countdown --
---------------------------

        for i = 3, 1, -1 do
            h.Text = "Game begins in: " .. i
            wait(1)
        end

-------------------------------
-- Countdown till round ends --
-------------------------------

        for i = 10, 1, -1 do
            h.Text = "Time left: " .. i
            wait(1)
        end
        h.Text = "The round has ended"
        wait(1)

------------------------------------        
-- Teleport players back to lobby --
------------------------------------

        for i,v in pairs(game.Players:GetPlayers()) do
            v.Character:MoveTo(Vector3.new(108, 11.19, -29))
        end
        wait(1)
        mapChosenClone:Destroy()

------------------------------------------------------
-- Tells the player their needs to br 1 more player --
------------------------------------------------------

    else
        h.Text = "You need 1 more player to join"
    end
    wait(1)
end

1 answer

Log in to vote
0
Answered by 10 years ago

Why can't it kill them? There is a method called :LoadCharacter() which instantly respawns them.

players = game.Players:GetChildren()
    local randomp = players[math.random(1,#players)]
    print(randomp.Name .. " is killer")
    randomp.TeamColor = BrickColor.new("Bright red")
    randomp:LoadCharacter()
    for i,v in pairs(players)  do
        if v.Name ~= randomp.Name then
            print(v.Name .. " is runner")
            v.TeamColor = BrickColor.new("Bright blue")
        v:LoadCharacter()
        end
    end
0
Cause I'm making a deathrun game. So there is only ONE spawn, and thats loby. The runner and kiler spawns are just blocks, not a spawnlocation. Pretty much all I need is there team to change, thats it NinjoOnline 1146 — 10y
0
What are the spawn's names? YaYaBinks3 110 — 10y
0
Sorry, the blocks they spawn on* YaYaBinks3 110 — 10y
0
Ok, so there in a map called "Plates" and within the map, there are 2 models, "RunnerSpawn" and "KillerSpawn" and then within them their are "Spawn" NinjoOnline 1146 — 10y
View all comments (6 more)
0
I can add the before and after part to the script? NinjoOnline 1146 — 10y
0
OK, thanks, sooo much, it put the players in team perfectly, but they just fall out of the world NinjoOnline 1146 — 10y
0
Could the load character be breaking it, cause I have it set out so once the round if over it takes all the players back to lobby. I'll post the whole script below NinjoOnline 1146 — 10y
0
Yes, I'll be back in around an hour. cya soon YaYaBinks3 110 — 10y
0
ok NinjoOnline 1146 — 10y
0
you back yet? NinjoOnline 1146 — 10y
Ad

Answer this question