How can I put all players in a folder when they join to the game?

@NotWhutThe is probably correct then, why do you want to put the characters in a folder?

Again, I want test something. Please dont discuss about what I do need and what not. If you want help me then help. If you want discuss - what I do need - then this is the wrong comment section for you.

Never use while true do loops like that, itā€™s unnecessary when weā€™re waiting for an event (In this case, players added), all it does now is cause tremendous lag.

2 Likes

Maybe you can add object values to a folder instead of the character?

local Players = game:GetService("Players")
local Folder = workspace:WaitForChild("npc_directory")
Players.PlayerAdded:Connect(function(Player)
        local Value = Instance.new("ObjectValue",Folder)
        Value.Value = Player
        Value.Name = Player.Name
end)

Hello there! I have made a working script for you.

  1. Your Explorer menu must look like this;

Explorer

  1. Put this script into ā€œServerScriptServiceā€.

    local Players = game:GetService("Players")
    
    Players.PlayerAdded:Connect(function(plrAdded)      -- It checks if a player joined the game.
    plrAdded.CharacterAdded:Connect(function(charAdded)     -- It checks if a player's character joined the game.
     
     wait(1)      -- If you don't add this, it won't work.
     
     local PlayerCheck = Players:GetPlayerFromCharacter(charAdded) -- Gets player from the character
     
     local Model = game.Workspace:FindFirstChildWhichIsA("Model") -- Checks if the class name is "Model"
     local ModelName = Model.Name
     
     if ModelName == PlayerCheck.Name then
     	Model.Parent = game.Workspace.npc_directory -- Puts the model into the folder
     end
    end)
    end)
    
  2. Here is how it works:

EDIT: You donā€™t need to use Clone() function or donā€™t need to create a value using Instance.new

This is the simplest way that you can use.

1 Like
game:GetService("Players").PlayerAdded:Connect(function(player)
       player.CharacterAdded:Connect(function(character)
              repeat game:GetService("RunService").Heartbeat:Wait() until character:IsDescendantOf(workspace)
              character.Archivable = true
              character.Parent = workspace.npc_directory
       end)
end)

this should work

3 Likes

give someone the soulituonnnnnn

just add wait before changing a parent , hereā€™s code sample :

game.Players.PlayerAdded:Connect(function(player: Player)
	player.CharacterAdded:Connect(function(character: Model)
		task.wait(1) --The solution
		character.Parent = --Folder where player should be
	end)
end)

That was three years ago when I didnā€™t know how to script, but thanks.

2 Likes