Hello, I am trying to read & edit Client, Server & Module code with a plugin.
In this current example I’m trying to find the word Banana and change it
with Apple. It does print, but it does not change.
local ScriptEditorService = game:GetService("ScriptEditorService")
local Selection = game:GetService("Selection")
local function replaceBananaWithApple(Script)
local source = Script.Source
local modifiedSource = source:gsub("Banana", "Apple")
if source ~= modifiedSource then
Script.Source = modifiedSource
print("Replaced 'Banana' with 'Apple' in script:", Script:GetFullName())
end
end
local function onScriptChanged(Script)
if Script:IsA("LuaSourceContainer") then
replaceBananaWithApple(Script)
end
end
ScriptEditorService.TextDocumentDidChange:Connect(function(doc)
local Script = doc:GetScript()
if Script then
replaceBananaWithApple(Script)
end
end)
I’ve seen that it is possible, here are some sources.
But I cannot get it to work.
When you use a Plugin that modifies or peeks at your code, (Haven’t checked that yet…) it must require you, the user to accept that you know what this Plugin does, and if you’re okay with it.