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

How can I change the team of all the players in the server? [closed]

Asked by 3 years ago
Edited 3 years ago

So in this script, what I'm trying to do is have all the players in the game go on the team "Players" as Intermission ends.

local roundLength = 180
local intermissionLength = 5
local InRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local teamPlaying = Teams.Playing
local teamSpectators = Teams.Spectating


local LobbySpawn = game.Workspace.LobbySpawn
local GameAreaSpawn = game.Workspace.GameAreaSpawn
local Part = workspace.LobbyFloor

InRound.Changed:Connect(function()
    wait(1)
    if InRound.Value == true then
        Part.CanCollide = false

        wait(2)
        Part.CanCollide = true

    else
        for _, player in pairs(game.Players:GetChildren()) do

            local char = player.Character
            char.HumanoidRootPart.CFrame = LobbySpawn.CFrame
        end
    end
end)



local function roundTimer()
    while wait() do
        for i = intermissionLength, 1, -1 do
            InRound.Value = false
            wait(1)
            Status.Value = "Intermission: ".. i .." seconds left!"
        end
        for i = roundLength, 1, -1 do
            InRound.Value = true
            wait(1)
            Status.Value = "Game: ".. i .." seconds left!"
            local function onPlayerDied(player, character)
                -- When someone dies, put them on the spectator team
                player.Team = teamSpectators
            end
        end
    end
end

spawn (roundTimer)

I attempted to try and put code on line 19 stating player.Team = teamPlaying but that did not work. To make the script work, the script above needs to be placed in ServerScriptService and a script called LocalScript that's in Starter Gui under a ScreenGui named Timer and beside text that's named TimerDisplay. Also need an int value called InRound in ReplicatedStorage and a String value named Status. The following is localscript

local Status = game.ReplicatedStorage.Status
local TimerDisplay = script.Parent.TimerDisplay

Status.Changed:Connect(function()
    TimerDisplay.Text = Status.Value
end)

Closed as Non-Descriptive by JesseSong

This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.

Why was this question closed?