@Salinas23 Ahh you’re right!
I think the problem might be that you’re using “game.StarterPlayer” instead of the specific player’s StarterPlayer. I switched the function to “PlayerAdded”, and specifically referred to the player’s StarterPlayer. I’m not sure if it’s possible to do this through a server script, however we’ll see how it goes.
Also, I accidently used “return” instead of “break” at one point.
Try this, and tell me what works/doesn’t and what it prints (added prints to check on table):
local cs = workspace.CharacterSelect
local charTable = {
{Name = cs.Adam, num = 0, taken = false},
{Name = cs.Marcos, num = 0, taken = false},
{Name = cs.Bryan, num = 0, taken = false},
{Name = cs.Chad, num = 0, taken = false},
{Name = cs.Chelsea, num = 0, taken = false},
{Name = cs.Emily, num = 0, taken = false},
{Name = cs.Issac, num = 0, taken = false},
{Name = cs.Todd, num = 0, taken = false},
{Name = cs.Mike, num = 0, taken = false}
}
Players.PlayerAdded:Connect(function(player)
-- Check what shows up in table at start of ChildAdded
for _, char in pairs(charTable) do
print("CharName: " .. char.Name)
print("Num: " .. char.num)
print("Taken: " .. char.taken)
end
-- Function to scramble the characters in the table
local function scrambleTable()
for _, character in pairs(charTable) do
character.num = math.random(1, 100)
end
table.sort(charTable, function(a, b)
return a.num < b.num
end)
end
-- To pick a character for the player to become
local function pickCharacter()
for _, pick in pairs(charTable) do
if pick.taken == false then
local character = pick.Name
local randchar = character:Clone()
randchar.Name = "StarterCharacter"
randchar.Parent = player.StarterPlayer
pick.taken = true
break
end
end
end
scrambleTable()
pickCharacter()
-- Check what shows up in table after everything else (see if everything worked)
for _, char in pairs(charTable) do
print("CharName: " .. char.Name)
print("Num: " .. char.num)
print("Taken: " .. char.taken)
end
end)