Trying to parent a folder in Replicated Storage to each player but can't seem to achieve it

Hello! I’m trying to parent a clone of a folder from Replicated Storage to each player but I don’t think it worked.

I checked myself in testing to see if it did parent me with the clone of the folder but I don’t think it did.

I used a server script and it is in sever script service but I think I should use a LocalScript?

Here is my script:

local RS = game.ReplicatedStorage

local charVariable
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Wait()
	charVariable = player.Character
	local folder = RS:WaitForChild("EditorFolderEx")
	local folderClone = folder:Clone()
	folderClone.Name = charVariable.."EditorFolder"
	folderClone.Parent = charVariable
end)
2 Likes

What you wrote looks like it should work just fine. Do you mean to put it into the Player or Character? Because you’re currently putting it into the Character and only the first time they spawn.

I want it to add it to the player in workspace every time they join

So what you’d be talking about is the Player’s Character. The Player and Character are completely different, so it’s important to make that clear.

If you’re adding something to the character, you should know that it won’t be there if the player respawns their character. The way you have this currently written will only add it the first time their character spawns.

The script looks fine otherwise, although it could be shortened a bit (not that it really makes a difference).

Edit:
Actually, I do see one problem.

folderClone.Name = charVariable.."EditorFolder"

Where charVariable is an instance and not a string. For that, just do:

folderClone.Name = charVariable.Name.."EditorFolder"
2 Likes

I’m still confused about this, how do I fix it that it still keeps the folder when player reset?

1 Like

This should work:

local RS = game.ReplicatedStorage

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local folder = RS:WaitForChild("EditorFolderEx"):Clone()
		folder.Name = player.Name..folder.Name
		folder.Parent = character
	end)
end)

However, I would recommend storing these folders inside the Player instead of the Character as the Player instance will never ‘respawn’. Either that or store them in ReplicatedStorage which is even safer than either as they won’t unexpectedly vanish if the player leaves the game, which could cause errors if not handled correctly.

1 Like

Do you I just change it to player rather than Character?

1 Like

Why use .ChildAdded() when you could just use .CharacterAdded()? Unless this was accidental, I’d do it like so:

local Players = game:GetService("Players")
local RepStorage = game:GetService("ReplicatedStorage")

local function onPlayerAdded(player)
    local function onCharacterAdded(character)
        local folder = RepStorage:WaitForChild("EditorFolderEx"):Clone()
        if folder then
            folder.Name = player.Name .. folder.Name
            folder.Parent = character
        end
    end
    if player.Character then
        onCharacterAdded(player.Character)
    end
    player.CharacterAdded:Connect(onCharacterAdded)
end

for _,p in pairs(Players:GetPlayers()) do onPlayerAdded(p) end
Players.PlayerAdded:Connect(onPlayerAdded)
1 Like

Studio’s auto-complete seems to prefer ChildAdded over CharacterAdded, which really doesn’t make sense considering CharacterAdded is Alphabetically first and more common in that situation.

1 Like

You can if you’d prefer. You could even just put the folder in StarterPlayerScripts or StarterGui and it’ll end up in its respective folder without any code needed.

1 Like

Well, I want each player to have a camera part that’s facing them so I think cloning the folder and then naming them will help specify the folder easier.

1 Like