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

Why doesn't this place players in random teams?

Script inside serverscriptservice, no errors, it just doesn't do anything.

local replicatedstorage = game:GetService('ReplicatedStorage')
local status = replicatedstorage:WaitForChild('InfoValue')

function randomTeams(player)
if status.Value == "Map Spawned, prepare to fight soon!" then
local teamValue = game.ServerScriptService.MainScript.TeamValue.Value
local teamBlue = game.ServerStorage.Blue:Clone()
local teamRed = game.ServerStorage.Red:Clone()
teamRed.Parent = game.Teams
teamBlue.Parent = game.Teams
if teamValue == 1 then
player.TeamColor = BrickColor.new("Really red")
teamValue = 2
elseif teamValue == 2 then
player.TeamColor = BrickColor.new("Really blue")
teamValue = 1
end
end
end

randomTeams()

2 answers

You fired "randomTeams" expecting a "player" parameter but not providing one. Also, you ran it expecting that each player would be looped through it, when in reality none are. I suggest removing the player parameter and adding a loop for every player. Also, when checking an Instance's value as a variable, don't include ".Value" in the variable declaration, it messes things up. Here, I'll show you:

local replicatedstorage = game:GetService('ReplicatedStorage')
local status = replicatedstorage:WaitForChild('InfoValue')

function randomTeams()
if status.Value == "Map Spawned, prepare to fight soon!" then
local teamValue = game.ServerScriptService.MainScript.TeamValue
local teamBlue = game.ServerStorage.Blue:Clone()
local teamRed = game.ServerStorage.Red:Clone()
teamRed.Parent = game.Teams
teamBlue.Parent = game.Teams
for _,plr in pairs(game.Players:GetChildren()) do
if teamValue.Value == 1 then
plr.TeamColor = BrickColor.new("Really red")
teamValue.Value = 2
else
if teamValue.Value == 2 then
plr.TeamColor = BrickColor.new("Really blue")
teamValue.Value = 1
end end end end end

randomTeams()

2 comments

0

That did the same thing no errors, but it just didn't work. Is this supposed to be in a local or server script?

0

It should be in a server script.

If this still doesn't work, just double check that on the team spawns, they aren't neutral or auto-assignable

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