Team is not a valid member of StarterGear "Players.Player2.StarterGear"

I stumbled upon a strange error. I have not found a solution to this problem on the Internet. maybe you can help?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local lobby = game.Workspace.Spawn
local maps = ReplicatedStorage.Maps:GetChildren()
local status = ReplicatedStorage.Status
local duelteam = game.Teams.Duelists
local lobbyteam = game.Teams.Lobby
while true do
	local players = Players:GetPlayers()
	players.Team = lobbyteam
	if #players >= 2 then
		for i = 5, 0, -1 do
			status.Value = "Intermission:" .. i
			wait(1)
		end
		local chosenmap = maps[math.random(1, #maps)]
		local clonemap = chosenmap:Clone()
		clonemap.Parent = workspace
		status.Value = "Map:" .. clonemap.Name
		wait(2.5)
		local chosenplayer1 = players[math.random(1, #players)]
		local chosenplayer2 = nil
		repeat
			wait()
			chosenplayer2 = players[math.random(1, #players)]
		until chosenplayer2 ~= chosenplayer1
		chosenplayer1.Character:SetPrimaryPartCFrame(clonemap.Teleport1.CFrame)
		chosenplayer1.Team = duelteam
		chosenplayer2.Character:SetPrimaryPartCFrame(clonemap.Teleport2.CFrame)
		chosenplayer2.Team = duelteam
		chosenplayer1.Character:WaitForChild("Humanoid").Died:Connect(function()
			chosenplayer1.Team = lobbyteam
		end)
		chosenplayer2.Character:WaitForChild("Humanoid").Died:Connect(function()
			chosenplayer2.Team = lobbyteam
		end)
		for i = 10, 0, -1 do
			status.Value = "Liquidation:" .. i
			local playing = {}
			for i, plr in pairs(chosenplayer1:GetChildren()) do
				if plr.Team.Name == "Duelists" then
					table.insert(playing, plr.Name)
				end
			end
			for i, plr in pairs(chosenplayer2:GetChildren()) do
				if plr.Team.Name == "Duelists" then
					table.insert(playing, plr.Name)
				end	
			end
			if #playing == 0 then
				status.Value = "The duelists died"
				wait(3)
				break
			end
			if #playing == 1 then
				status.Value = playing[1].Name.."Has WON!"
				wait(3)
				break
			end
			wait(1)
			if i == 0 then
				local sound = game.ReplicatedStorage["kid fav blinker"]
				sound:Play()
				wait(0.7)
				chosenplayer1.Character.Humanoid.Health = 0
				chosenplayer2.Character.Humanoid.Health = 0
				status.Value = "Explosive draw!"
				wait(3)
			end
		end
		clonemap:Destroy()
		chosenplayer1.Character:SetPrimaryPartCFrame(lobby.Tp1.CFrame)
		chosenplayer1.Team = lobbyteam
		chosenplayer2.Character:SetPrimaryPartCFrame(lobby.Tp2.CFrame)
		chosenplayer2.Team = lobbyteam
	else
		status.Value = "You're unlikely to play alone."
		wait(0.5) 
		status.Value = "You're unlikely to play alone.."
		wait(0.5)
		status.Value = "You're unlikely to play alone..."
		wait(0.5)
	end
end
1 Like

The problem is that you are using :GetChildren(). That is getting everything inside your player instance including the StarterGear folder. What you should do is check chosenplayer1.Team

It appears to me that you’re assigning the variables “chosenplayer1” and “chosenplayer2” as random players from the game and then rerolling until they’re different players, meaning those variables are already player instances.

While trying to set a player to a table, you’re checking “plr.Team.Name”, with “plr” being an argument specific only to the for loop, as a child of the “chosenplayer1/2” variable. When doing so, plr becomes a child of the player per every iteration of the loop, meaning that plr would be:
PlayerScripts
Backpack
…

In order to fix this issue, you’ll want to remove the for loop and just use the “if” statement embedded within those for loops, tweaked a little, so that the following lines:

for i, plr in pairs(chosenplayer1:GetChildren()) do
	if plr.Team.Name == "Duelists" then
		table.insert(playing, plr.Name)
	end
end
for i, plr in pairs(chosenplayer2:GetChildren()) do
	if plr.Team.Name == "Duelists" then
		table.insert(playing, plr.Name)
	end	
end

are now replaced with:

if chosenplayer1.Team.Name == "Duelists" then
	table.insert(playing, chosenplayer1)
end

if chosenplayer2.Team.Name == "Duelists" then
	table.insert(playing, chosenplayer2)
end

Let me know if this work for you.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.