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

Is it possible to insert text into a script by using a script?

I'm attempting to make a script that will move a script to somewhere else, and insert a script into it, it would take a bit of time to do this in more than one script, so I'm trying to save time by doing it in one.

I am needing help with the part that involves inserting a selected script into the script.

a = Instance.new("LocalScript",game.Workspace) --Creates a localscript in workspace
a.Name = ("LSName") --Changes the localscripts name.

chatt = game.Players.LocalPlayer --This is the player the command will go to
function onChatted(msg) --This is the function for the chat command

if msg == "InsertMessage" then --This is the message the player must say for the script to happen

--This is the script that will happen if the command is said

end
end

chatt.Chatted:connect(onChatted) --This connects the function

local var = game.Workspace.LSName:Clone() --This clones the script this is in to var's parent in line 17
var.Parent = game.StarterPlayer.StarterPlayerScripts --This is the target for line 16

1 answer

✓ Accepted answer

I'm not sure if this is the solution to your issue, because I'm not completely sure what the issue you're having is, but to move a script into a Player's PlayerScripts, you use Player.PlayerScripts, not StarterPlayer.StarterPlayerScripts. The latter code will not cause the script to run unless a player joins after the change has been made.

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