So I am trying to make it so that a script gets made via another script. And then I want to insert code inside of the new script. But I am not sure how to do so.
I don’t think there is a way to add a script into things and edit it entirely through a script (could be wrong), but even if there was there is a much more efficient way of going about it using clone:
https://developer.roblox.com/en-us/api-reference/function/Instance/Clone
To go about it using this method you would want to write the script and then put the script in ServerStorage or ReplicatedStorage depending on the use.
-- Then reference the script using a variable local ScriptToReplicate = game.ReplicatedStorage.ScriptName -- Then clone it into the Workspace (or your desired location) local ReplicatedScript = ScriptToReplicate:Clone() -- Then reference the parent of the script using a variable ReplicatedScript.Parent = game.Workspace
As I said it doesn’t necessarily have to be cloned into Workspace, all you need to do to change the location is change game.Workspace to your chosen location.
Easiest way:
local Script = Instance.new("Script",workspace) local ScriptSource = "print("HAHA GET PRANKED IT ISNT ‘HELLO WORLD’ HAHAHA")" Script.Source = ScriptSource