Edit specific lines of script.source

Hey there, I am wondering if there is a way to edit specific lines of script.source via a plugin

I am trying to make a plugin for friends in a community I am a part of that adds extra features to something they already may have without having to go into the script’s code and try and copy / paste it. So I am designing something that will go and modify parts of the script to fix it for them.

Example:

1  local thing = 1+2
2  print("Hello World!")
3  print(5*thing)

How would I just be able to modify either specifically line 3, or modify specifically what would match print(5*thing)

*Note, I was unable to find any topics like this, just ones talking about script.source being used only with cmd line or plugins.

I am open with any answers / solutions

you could use string.split to get each line and since split returns a table, you can just index the table with the line number to get the line


local Source = Script.Source
local Lines = string.split(Source,"\n")

local Line3 = Lines[3]
Line3 = "print(10*Thing)"

Source = table.concat(Lines,"\n")
Script.Source = Source

Thank you, I will go ahead an try that!

EDIT: it worked, thank you for that!