Teams reporting Nil

I need help. I am trying to make a system to get the scores of teams, but it is not working. The teams in my table are either not being found, or there is something wrong with my syntax or timing.

The portion that is not working:

for i,v in pairs(teams) do
		print(v)
		print(v.Name)
		local score = game.ServerStorage.Scores:WaitForChild(v.Name.." Score").Value
		local tps = v:GetPlayers()
		for a,b in pairs(tps) do
			b.leaderstats.Points.Value += score
		end
		scores[#scores+1] = {score,v.Name}
	end

The entire script:

while true do
	local players = game.Players:GetPlayers()
	for i,v in pairs(players) do
		v.PlayerGui.FinishUI.Enabled = false
		game.ReplicatedStorage["Main System"].SetDefaultCam:FireClient(v)
	end
	game.Workspace.StageSpawn.TeamColor = BrickColor.new("Really black")
	game.Workspace.Music.SoundId = "rbxassetid://9043887091"
	game.Workspace.Background.Decal.Texture = "rbxassetid://3899340539"
	for i=1,30 do
		game.ReplicatedStorage["Main System"].UpdateText:FireAllClients("Intermission: "..tostring(30 - i))
		wait(1)
	end
	game.ReplicatedStorage["Main System"].TeleToTeams:Fire()
	
	for i,v in pairs(players) do
		game.ReplicatedStorage["Main System"].SetDefaultCam:FireClient(v)
		
	end
	for i=1,15 do
		game.ReplicatedStorage["Main System"].UpdateText:FireAllClients("Choose a team, "..tostring(15 - i).." seconds left")
		wait(1)
	end
	local teams = game.Workspace.TeamSelectors:GetChildren()
	for i,v in pairs(teams) do
		local t = game.Workspace:GetPartsInPart(v)
		for a,b in pairs(t) do
			if game.Players:GetPlayerFromCharacter(b.Parent) ~= nil then
				print("Player")
				game.Players:GetPlayerFromCharacter(b.Parent).TeamColor = game.Teams:FindFirstChild(v.Name).TeamColor
			end
		end
	end
	game.ReplicatedStorage["Main System"].SetViewCam:FireAllClients()
	local teams = game.Teams:GetTeams()
	for i,v in pairs(teams) do
		local tp = {}
		script.CurrentTeam.Value = v
		game.Workspace.Music.SoundId = ""
		game.Workspace.Music.TimePosition = 0
		game.Workspace.Background.Decal.Texture = "rbxassetid://3899340539"
		local plrs = game.Players:GetPlayers()
		for a,b in pairs(plrs) do
			if b.Team == v then 
				tp[#tp+1] = b
				game.Workspace:FindFirstChild(b.Name):MoveTo(game.Workspace.StageSpawn.Position)
				b.PlayerGui.StageUI.Enabled = true
				b.PlayerGui.ViewerUI.Enabled = false
			else
				b.PlayerGui.StageUI.Enabled = false
				b.PlayerGui.ViewerUI.Enabled = true
			end
			if b.Team == game.Teams.Lobby then
				game.Workspace:FindFirstChild(b.Name).Humanoid.Health = 0
			end
			wait(2)
		end
		if #tp > 0 then
		wait(1)
		for i=1, #tp*60 do
			game.ReplicatedStorage["Main System"].UpdateText:FireAllClients(tostring(#tp*60 - i))
			wait(1)
			end
			for r,k in pairs(tp) do
				game.Workspace:FindFirstChild(k.Name).Humanoid.Health = 0
				k.PlayerGui.StageUI.Enabled = false
				k.PlayerGui.ViewerUI.Enabled = true
			end
			wait(2)
	end 
	end
	
	game.ReplicatedStorage["Main System"].SetDefaultCam:FireAllClients()
	
	local scores = {}
	local teams = game.Teams:GetTeams()
	for i,v in pairs(teams) do
		print(v)
		print(v.Name)
		local score = game.ServerStorage.Scores:WaitForChild(v.Name.." Score").Value
		local tps = v:GetPlayers()
		for a,b in pairs(tps) do
			b.leaderstats.Points.Value += score
		end
		scores[#scores+1] = {score,v.Name}
	end
	for i,v in pairs(players) do
		
		for a,b in pairs(scores) do
			v.PlayerGui.FinishUI.Frame:FindFirstChild(b[1]).Text = b[1]..": "..tostring(b[2])
		end
		
		v.Team = game.Teams.Lobby
		v.PlayerGui.ViewerUI.Enabled = false
		v.PlayerGui.StageUI.Enabled = false
		v.PlayerGui.FinishUI.Enabled = true
	end
	wait(10)
	for i,v in pairs(players) do
		v.PlayerGui.FinishUI.Enabled = false
		game.Workspace:FindFirstChild(v.Name).Humanoid.Health = 0
	end
	end

I am also having a similar problem with making the score givers, except there are no errors showing up in console.

local s = 0
local hl = false
local hdl = false
script.Parent.StateChangeRequest.Event:Connect(function(r)
	if s ~= r then
		
		if r == 1 then
			if s == 0 then 
			game.ServerStorage.Scores:FindFirstChild(game.ServerScriptService.Events.CurrentTeam.Value.Name.." Score").Value += 1
			end
			if s == 2 then 
				game.ServerStorage.Scores:FindFirstChild(game.ServerScriptService.Events.CurrentTeam.Value.Name.." Score").Value += 2
			end
		end
		
		if r == 1 then
			if s == 0 then 
				game.ServerStorage.Scores:FindFirstChild(game.ServerScriptService.Events.CurrentTeam.Value.Name.." Score").Value -= 1
			end
			if s == 1 then 
				game.ServerStorage.Scores:FindFirstChild(game.ServerScriptService.Events.CurrentTeam.Value.Name.." Score").Value -= 2
			end
		end
		
	end
end)

*The variables “hl” and “hdl” were not used due to finding a simpler way of doing their original task.

The respawn time has been set to 0, but it usually takes a split second, so I added some extra waiting time.

The game is a game where players go into teams, act out a play, and then see how players rate them. (Just so you know)

I have tried several things to solve this, such as making the “teams” variable global, and copy-pasting the original definition of the variable to where it is being used. So far, nothing has worked.

Also, please point out any other errors you find in my code. (I am well aware that I am supposed to use “task.wait()” and not just “wait()”, but it is mostly the same)

bump

Hello I see you have 2 different “teams” variables so that could be your problem. I would change the top one to

local Teams = game.Workspace.TeamSelectors:GetChildren()
	for i,v in pairs(Teams) do
		local t = game.Workspace:GetPartsInPart(v)
		for a,b in pairs(t) do
			if game.Players:GetPlayerFromCharacter(b.Parent) ~= nil then
				print("Player")
				game.Players:GetPlayerFromCharacter(b.Parent).TeamColor = game.Teams:FindFirstChild(v.Name).TeamColor
			end
		end
	end

ill try it

it didnt work :frowning:

What did it do, anything different? Can you show me your teams in explorer?

ok, here:




by the way, closed instances are instances that are not modified by me

thanks. it looks like you forgot the rest of this?

should it be all clients?

so i am going through all this and trying to recreate what i can but the first thing i needed to do was make a wait before the while true do because the script loads before the players. other wise its running down to the change of text at the bottom.

the first few things before intermission countdown are not important. They are just for resetting stats already in-game players.

no, the message is serverside only. (The script in StarterCharaterScripts handles the teleports)

Ok so right after the local players add

print(players)

I feel it will come back as empty so if that’s so make a wait and see if the rest of the script runs.

it does repeat empty, so I added the wait and the table was filled, but the problem is still there.