Hi, I am trying to have a function loop through all of the players and give them a character to play as, but it’s not working. Here is my script:
function module.DressPlayers()
for i, player in pairs(game.Players:GetPlayers()) do
if player.Character then
for _, character in pairs(game.ReplicatedStorage.PlayableCharacters:GetChildren()) do
local random = Random.new()
local characters = game.ReplicatedStorage.PlayableCharacters:GetChildren()
local chosenCharacter = characters[random:NextInteger(1,#characters)]
chosenCharacter.Name = player.Name
player.Character = chosenCharacter
chosenCharacter.Parent = workspace
end
end
end
end
It is working! I figured out the issue. Here is my working code:
function module.DressPlayers()
for i, player in pairs(game.Players:GetPlayers()) do
if player.Character then
local random = Random.new()
local characters = game.ReplicatedStorage.PlayableCharacters:GetChildren()
local chosenCharacter = characters[random:NextInteger(1,#characters)]
chosenCharacter.Name = player.Name
player.Character = chosenCharacter
chosenCharacter.Parent = workspace
end
end
end