This player loop isn't applying accessories to multiple players properly

I’ve been trying for a while with many different methods for saving characters after resetting and I’m pretty close with this, but I have an issue. It works perfectly fine with 1 player, but it doesn’t work for any players besides the first one.

Whenever a player chooses cosmetics, it’s added to a server script’s dictionary through a remote event, the player’s name is stored and an array is added to the dictionary entry that has the player’s cosmetics.

Though, whenever there is more than 1 player, it ends up only giving the cosmetics to 1 player and not the other.

image
Here it shows that both players have a dictionary spot and their own array, but only one actually receives the hair. Any help would be appreciated!
image

I think you should place the loop inside the event instead. What i meant is place the for i,player
inside the player.CharacterAdded event

Well I don’t think that’d work because CharacterAdded checks for a specific player, I need to check every player in order to know which one is adding a character.

Your loop only loop one time through all players tho but what if another player loaded and the loop doesn’t happen it won’t add the hair to that player. By doing that whenever a character loaded the loop will run again through all players again. Or i am miss understanding something

Why are you using:

tostring(player.Name)

Isn’t the player name already a string? Also, perhaps Player 2 hasn’t loaded in yet. Instead of looping through it once, try to use Players.PlayerAdded. If that doesn’t work or I’m misunderstanding what the script does at what time, you can wait for the character to fully load or use task.wait()

EDIT: Also, I noticed that you have a variable called “players” yet it is never used and you just use game.Players. Using game:GetService(“Players”) will probably do you better.

1 Like