Character Randomizer

I am making a Character Randomizer system where everytimme a new player starts playing they get one of selected characters and I have some code but it doesnt work, can anyone help? there is a screenshot and code below
Characters

-- In a script in ServerScriptService

local characters = game.ServerStorage:WaitForChild("Characters"):GetChildren() -- replace with where the folder is and the name of the folder

game.Players.PlayerAdded:Connect(function(player)
	if #characters > 0 then
		local function assignCharacter()

			local starterChars = {}

			for i, char in ipairs(characters) do
				table.insert(starterChars, char)
			end

			local function randomCharacter()
				local random = Random.new()
				return starterChars[random:NextInteger(1, #characters)]
			end

			local newChar = randomCharacter():Clone()	

			player.Character = newChar
			newChar.Parent = workspace
			player.Character:WaitForChild("HumanoidRootPart").CFrame = workspace.Map.SpawnLocation.CFrame -- Line Added. Replace SpawnLocation with the name of the spawn point
		end

		player.CharacterAdded:Connect(function(c)
			local h = c:WaitForChild("Humanoid")
			h.Died:Connect(function()
				task.wait(3)
				assignCharacter()
			end)
		end)

		assignCharacter()
	else
		print("There are no starter characters in StarterPlayer.")
		player:LoadCharacter()
	end
end)

I wouldve done this way differently, so ur trying to get different character each time some dude respawns?

No im trying to make it so every player gets a rqandom character that they will always have after joining for the first time

So a server has 50 plrs but u want to give them a option of 4 random charso u need to kick like 46?

No I mean that every player gets a randomly chosen character, I am going to make more character models and make the servers smaller so that I dont have to make that many characters

Did u use AI to make ur current script because ai wont help you.
I will give you a explanation later okay?

2 Likes