local Team1 = game:GetService("Teams")["TestTeam"]
local Team2 = game:GetService("Teams")["In-Game"]
local Player = game:GetService("Players").LocalPlayer
while true do
for i = 1,10 do
status.Value = "New Round Starting In ".. 10-i
wait (1)
end
local rand = math.random(1, #maps)
local map = maps[rand]:Clone()
map.Parent = workspace
print("clone")
status.Value = "Regenerating Map! "..map.Name
wait(4)
local players = game.Players:GetChildren()
for i = 1,#players do
if players[i].Character ~= nil then
wait(3)
local plrs = game.Players:GetChildren()
for i = 1,#plrs do
if Player.Team1 == "TestTeam" then -- Check Users Team
print("USER IS ON TEST TEAM")
if Player.Team2 == "In-Game" then
print("USER IS IN GAME")
end
Could you explain why there are two loops over game.Players:GetChildren()?
I think you will have a lot of other issues but the error you pointed out is likely because you are referencing LocalPlayer in a server script or the local player has died. Change the Player.Team1 to plrs[1].Team1 or replace your second loop with the following
local plrs = game.Players:GetPlayers()
for _, plr in ipairs(plrs) do -- using ipairs instead of indexed looping
if plr.Team1 == "TestTeam" then
print("USER IS ON TEST TEAM")
if plr.Team2 == "In-Game" then
print("USER IS IN GAME")
end
end
Not sure why there are two loops, its a code from ages ago, and i decided to change it around.
Yes, i was referencing LocalPlayer in a server script, my mistake. The code you provided seems to interfere with other code below, i will try doing what you said here.