I've been looking for a way to make the number of scripts I have to change in a game of mine smaller (i.e. I'd only have to change one script), problem I haven't been able to find a way to do that locally, I've tried something to the tune of private modules (i.e. require(game:GetService("ReplicatedStorage").modulescript)
but I'm not sure how to get the module script to execute relative to the script that's calling it (or really how t execute at all, I'm thinking it should work somthing like an anti-exploit loader). I've looked into having a script clone the source of another script into itself, but I'm still not sure how to go about that.
Any ideas?
Thanks in advance.
Solutions:
game.ReplicatedStorage.SomeScript:Clone().Parent = script.Parent; script:Destroy()
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:
--Before 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 --Option #2, ModuleScript: return function(script) --above code here end --Option #2, calling script: require(game.ReplicatedStorage.TransparencyScript)(script) --Option #3, central script: local ch = workspace.Parts:GetChildren() --or if the parts aren't all in the same place: local ch = {workspace.Part1, workspace.SomeModel.Part2, --[[etc]]} 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.