Why am I getting " ServerScriptService.ManageClones:30: attempt to index a nil value"?

I am trying to clone an accessory from a folder in the player’s backpack into their character but I’m getting this error pop-up everytime I want it to clone.

Local Script:

        characterAddedRemote.OnClientEvent:connect(function()
    		local currentHat = currentHatFolder:GetChildren()
    	
    	
    		for i,v in pairs(currentHat) do
    		cloneCurrentHatRemote:FireServer(v, player.Character)
    		
    		end
    	end)

Server Script:

            cloneCurrentHatRemote.OnServerEvent:connect(function(hat, parent)
    	hat:Clone().Parent = parent
    end)

Why are both of the code snippets the exact same in your post?
If it’s supposed to be like that. Both OnClientEvent and :FireServer() cannot be used on a server-script.

Do the accessories on the client also exist on the server?

This makes no sense whatsoever as you can just do this on the server side. If client triggers it, use a remote event and tell server to do it anyway. You do not even need a characterAddedRemote as that also makes no sense, there is a CharacterAdded event.

The post was wrong, I have corrected it

Can CharacterAdded events be used in LocalScripts?

This again is a waste of time and also allows easy exploitability of items, just have server listen to when their character is added and put the items there…

The first return value of a RemoteEvent in FireServer() is the player whose client fired it, so hat would be the second argument received. @Wunder_Wulfe is correct in that this approach is futile either way though.

The server can’t access the folders in the backpack which is why I used a remote event to clone them.

This is your problem. When you try to send an instance over a remote event, it does not actually send a copy of that instance but instead a reference to that instance. If the accessory does not also exist on the server, this will not work. (Even if this pattern did work it would be horrible from a security perspective though, as players could wear anything)

Okay, I will try and find the hat that the player had equipped in RepStorage and clone it from there

With remote events, when you fire from the client to the server, the first parameter in the server code is the player that fired the event.

Instead of:

    cloneCurrentHatRemote.OnServerEvent:connect(function(hat, parent)
    	hat:Clone().Parent = parent
    end)

do

cloneCurrentHatRemote.OnServerEvent:connect(function(player, hat, parent)
	hat:Clone().Parent = parent
end)

I corrected that, thanks anyway.