✓ Accepted answer
Solutions:
game.ReplicatedStorage.SomeScript:Clone().Parent = script.Parent; script:Destroy()
- ModuleScripts (you could put your code in the ModuleScript, wrap it in a function, and call it; see below)
- Redesign your scripts to use tables/lists instead of copy/pasting your script for each item (you can also use ModuleScripts as collections of functions and/or places to hold data to be shared amongst multiple Scripts)
ex. Let's say you have a script that just keeps changing the transparency of its parent and want to change it so you don't have to copy/paste the script:
local p = script.Parent
while true do
for i = 0, 1, 0.1 do
p.Transparency = i
wait()
end
for i = 0.9, 0.1, -0.1 do
p.Transparency = i
wait()
end
end
return function(script)
end
require(game.ReplicatedStorage.TransparencyScript)(script)
local ch = workspace.Parts:GetChildren()
local ch = {workspace.Part1, workspace.SomeModel.Part2, }
while true do
for i = 0, 1, 0.1 do
for j = 1, #ch do
ch[j].Transparency = i
end
wait()
end
for i = 0.9, 0.1, -0.1 do
for j = 1, #ch do
ch[j].Transparency = i
end
wait()
end
end
I recommend option #3 as you can script which parts to use, rather than having to copy/paste the requiring script in option #2; it also is easier to coordinate changes to multiple objects when it's all handled in the same script. ex, if in the above scenario you wanted to make it so that the 2nd object was a bit delayed in its transparency changes compared to the 1st, there are ways to do that, and you'd only have to change this one script.
3 comments
regarding option #3, imagine doing that with lots of coins...
tho honestly i went with option #1
I'm not sure what you mean by "lots of coins" (or what you mean by that line) - done properly, option #3 is easier to maintain/modify than option #1 - after all, there's only the one script, rather than several. Option #1 is still reasonable, and preferable if you aren't good with tables yet.