Hey how can I put all players in a folder when they join in the game?
in serverscript
game.Players.PlayerAdded:Connect(function(player)
player:CharacterAdded:Connect(function(character)
character.Parent = npc_directory
end)
end)
Do what @PostVivic , and if you want to clone it, just turn off(or on) archivable on the players character and Clone()
it.
As I said it doesnt work I think because its a model idk
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character.Archivable = true
character.Parent = workspace.npc_directory
end)
end)
There is no reason to have all the players in a folder, just do
for index, player in ipairs(game.Players:GetPlayers()) do
local character = player.Character
if character then
print(character.Name)
end
end
Why do you actually want to do this? It’s probably not a good solution to you’re problem.
still doesnt work and why it is bad to do that?
Because why do you need to? It’s extremely inefficient because players are already in a folder, game.Players contains all the players,
I believe that code doesn’t work because CharacterAdded
fires before than the character is parented to workspace. Because of that it’s parented to workspace after that code parents it to the folder. This might work
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character.Archivable = true
character.AncestryChanged:Wait()
character.Parent = workspace.npc_directory
end)
end)
However, as others have said, there’s probably a better solution to your problem.
this works still not anyways I think I should not do that
while true do
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character.Archivable = true
character.AncestryChanged:Wait()
character.Parent = workspace.npc_directory
end)
wait()
end)
end
I don’t know if this works, but it’ll continuously check if there’s a new player when it’s run.
This did crash my Roblox Studio. Thanks for everyone helping me! But could you guys please test it before sending it to me? I mean this could change the length of this comment section.
put a script in game.StarterPlayer.StarterCharacterScripts saying
local Character = script.Parent
repeat
wait()
until Character and Character:FindFirstChild("Humanoid")
Character.Parent = workspace["npc_directory"]
still doesnt work idk why
I’m pretty sure roblox keeps it parented to game.Workspace, no matter what
does it show any errors in the output?
It doesnt work. No it doesnt show any problems.
Have you tried doing the code I sent?
Have you tried doing the code I sent?
yes it doesnt work