Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I copy something infinitely?

I have a script, I want to be able to copy from that script multiple times. If I were to write a = Script:Clone()

a.Parent = game.Workspace.player1

but were then too

a.Parent = game.Workspace.player2

It would move the copy to player2. What I want is to be able to copy a script from somewhere and whenever I want too be able to pull a copy of that script somewhere else so that I could use that same script multiple times. If this is still too confusing I'm sorry.

2 answers

✓ Accepted answer

You would need to have some kind of condition defined, and a separate script that copied the other script.

Let's say you have two scripts that are set up like this (just an example):


###Script #1 We'll say this is in ServerScriptService, and named 'Script1'. We'll also have it disabled.

while wait(5) do
	script.Parent.Head.BrickColor = BrickColor.random()
end

###Script #2 In Workspace

game.Players.PlayerAdded:connect(function(Plr) --Fires whenever a player is added to game
	Plr.CharacterAdded:connect(function(Char) --Fires whenever a character is added to workspace
		local ScriptClone = game.ServerScriptService.Script1:clone() --Clones it
		ScriptClone.Parent = Char --Moves the script to the player
		ScriptClone.Disabled = true --Allows the script to execute
	end)
end)

Now, basically what this would do is, whenever a players character is loaded into the game script 1 gets copied from ServerScriptService and put into the character. From then on, the script changes the characters head to a random color every 5 seconds.


Basically, this is just an example of a way that you could do this. If you have any further problems/questions, please leave a comment below, and I'll see what I can do. Hope I helped :P

####-Dyler3

The answer is really simple -- instead of moving a, copy a:

local template = workspace.Model:Clone()

local first = template:Clone() -- make another
first.Parent = workspace.Player1

local second = template:Clone() -- make another
second.Parent = workspace.Player2

For the future: When posting a question, make sure your use use the Lua formatting button in your question. Select the code and press the "Lua" button (purple circle). A line of ~~~ should appear before and after the code.

This discussion is preserved as it was. New answers, comments, and votes are closed.