Trying to clone a Folder and a Script for each player - not working?

Hi - I have a system built into a vehicle that controls a multitude of lights and sirens on the car - the changes need to happen on the server.

The script that does all of this works fine - I just need to clone a copy of the script and folder containing the RemoteEvents for each player that joins.

Here is my current script:

local FolderToClone = game.ReplicatedStorage.ELS.DuplicateEventFolder
local ScriptToClone = game.ServerScriptService.ELS.DuplicateScript

game.Players.PlayerAdded:Connect(function(Player)
	local ClonedFolder = FolderToClone:Clone()
	ClonedFolder.Name = Player.Name
	
	local ClonedScript = ScriptToClone:Clone()
	ClonedScript.Name = Player.Name
	ClonedScript.Enabled = true
end)

For reference, this is what the Explorer looks like:

image

At the moment it just won’t clone either of these two things. There are no errors being thrown up in the Output.

Any help would be greatly appreciated!

2 Likes

Clone() does not copy the Parent property from the original instances, so you have to add lines to set the Parent of both cloned items to where you want them, otherwise they won’t be in the datamodel, and because they are only set to local variables with the scope of your PlayerAdded handler function, they are both eligible for garbage collection and are probably getting deleted very soon after creation.

1 Like

This fixed it! Assigned the .Parent property of both clones immediately after creating them and they now appear.

Thanks!!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.