Heya folks! I took a break from scripting for a few months, and came back to it last week. I have scripted this piece of code that assigns players to a table randomly, and the table will be their team.
local storageRep = game.ReplicatedStorage
local status = storageRep:WaitForChild("Status")
game.Players.PlayerAdded:Connect(function(player)
--[[while game.Players.NumPlayers <= 1 do
status.Value = "PLEASE WAIT FOR ANOTHER PLAYER TO JOIN..."
end]]
for i = 10,0,-1 do
status.Value = "Round starting in "..i.." seconds"
wait(1)
end
for i,plr in pairs(game.Players:GetPlayers()) do
local teamSize = 5
local values = {"BlueTeam", "RedTeam"}
local plrTable = {}
local RedTeam = {}
local BlueTeam = {}
local teamName = Instance.new("StringValue")
teamName.Name = "TeamName"
teamName.Parent = plr
if teamName.Value == "" then
table.insert(plrTable,plr)
local randomChoice = math.random(1,#plrTable)
randomChoice.TeamName.Value = math.random(1,#values)
print(randomChoice.TeamName.Value)
table.insert(randomChoice.TeamName.Value,randomChoice)
table.remove(plrTable,randomChoice)
end
end
end)
However, I keep getting this error:
ServerScriptService.ScriptHolder:30: attempt to index number with ‘TeamName’
Any help? And any improvements to my original code after the fix?
Many thanks!