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

Why doesn't this place players in random teams?

Asked by 8 years ago

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

Log in to vote
0
Answered by
Uglypoe 557 Donator Moderation Voter
8 years ago

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()
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? CheekySquid 78 — 8y
0
It should be in a server script. Uglypoe 557 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

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

Answer this question