To reproduce, create a new experience, ensure Drafts mode is enabled, then run the following code in the command bar:
local ScriptEditorService = game:GetService("ScriptEditorService")
local myScript = Instance.new("Script")
myScript.Changed:Connect(print)
ScriptEditorService:UpdateSourceAsync(myScript, function()
return "Hello, cruel world!"
end)
myScript.Parent = workspace
After running this code, the script’s source is empty. Also observe that after running this code, the script’s Source property rapidly changes, and that Roblox Studio uses much more CPU than normal, even when running the example without the Changed connection.
This behavior does not occur when calling ScriptEditorService:UpdateSourceAsync
after parenting the new script. So, the problem can be worked around by parenting the script before updating the source - but considering that it’s generally good practice to set all of a newly created instance’s properties before parenting it, I think this is a sharp edge that should not exist.
This is a problem for any plugin that creates scripts and sets their sources using ScriptEditorService:UpdateSourceAsync
(which according to Roblox, is the preferred method to do so). It is specifically a problem for Rojo because some users may have Drafts mode enabled, and their scripts won’t sync properly.
I’m not sure when it started happening, but this behavior has probably existed since ScriptEditorService:UpdateSourceAsync
was first introduced.
Expected behavior
I expect that a plugin should be able to create a script, set its source using the recommended method, then set its parent, regardless of if Drafts mode is enabled or not.