i'm very bad at scripting in roblox but i would like to make a simple script that creates a script that has code written in it. i already figured out how to make a script without code. i just need to figure out how to put code in it when it's created
Well there isnt any way to code a script in a script, you could clone a premade script, There are other ways i think but im not sure how, hope this helped :)
I don't understand why you'd want to make a new script without cloning it. What you're asking is very much possible, however you'd need a plugin to do so.
A method of doing this would simply be to change the script.Source
.
This member cannot be used in scripts, but is usable in the command bar and plugins.
Intro to Plugins -developer site
This is literally copied FROM the link:
local ChangeHistoryService = game:GetService("ChangeHistoryService") -- Create a new toolbar section titled "Custom Script Tools" local toolbar = plugin:CreateToolbar("Custom Script Tools") -- Add a toolbar button named "Create Empty Script" local newScriptButton = toolbar:CreateButton("Create Empty Script", "Create an empty script", "rbxassetid://4458901886") local function onNewScriptButtonClicked() local newScript = Instance.new("Script") newScript.Source = "" newScript.Parent = game:GetService("ServerScriptService") ChangeHistoryService:SetWaypoint("Added new empty script") end newScriptButton.Click:Connect(onNewScriptButtonClicked)
A much, much easier way of doing this is not to use scripts, but rather loadstring.
WARNING: People somewhat dislike using loadstring, as it can be used as a tool for exploiters. Roblox is aware of this as well, thus you'd have to enable it via a property in ServerScriptService. (Link here.)
I can't find a link to loadstring itself, likely because it doesn't exist, but loadstring is pretty simple. You're able to run code if said code is a string. Example:
loadstring("print(hi)")() --loadstring is a function, so you need to use an extra ().
Alright, hope this helped! :D