diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ea6a1d5..c6991f01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,11 @@ * Added the `gameId` and `placeId` optional properties to project files. * When connecting from the Rojo Roblox Studio plugin, Rojo will set the game and place ID of the current place to these values, if set. * This is equivalent to running `game:SetUniverseId(...)` and `game:SetPlaceId(...)` from the command bar in Studio. -* Fixed `Name` and `Parent` properties being allowed in Rojo projects. ([#413](pr-413)) * Added "EXPERIMENTAL!" label to two-way sync toggle in Rojo's Roblox Studio plugin. +* Fixed `Name` and `Parent` properties being allowed in Rojo projects. ([#413][pr-413]) +* Fixed "Open Scripts Externally" feature crashing Studio ([#369][issue-369]) +[issue-369]: https://github.com/rojo-rbx/rojo/issues/369 [pr-413]: https://github.com/rojo-rbx/rojo/pull/413 ## [7.0.0-alpha.3][7.0.0-alpha.3] (February 19, 2021) diff --git a/plugin/src/ServeSession.lua b/plugin/src/ServeSession.lua index e8ab1e45..b40d8e81 100644 --- a/plugin/src/ServeSession.lua +++ b/plugin/src/ServeSession.lua @@ -1,4 +1,5 @@ local StudioService = game:GetService("StudioService") +local RunService = game:GetService("RunService") local Log = require(script.Parent.Parent.Log) local Fmt = require(script.Parent.Parent.Fmt) @@ -161,10 +162,18 @@ function ServeSession:__onActiveScriptChanged(activeScript) Log.debug("Trying to open script {} externally...", activeScript) - -- Force-close the script inside Studio - local existingParent = activeScript.Parent - activeScript.Parent = nil - activeScript.Parent = existingParent + -- Force-close the script inside Studio... with a small delay in the middle + -- to prevent Studio from crashing. + spawn(function() + local existingParent = activeScript.Parent + activeScript.Parent = nil + + for i = 1, 3 do + RunService.Heartbeat:Wait() + end + + activeScript.Parent = existingParent + end) -- Notify the Rojo server to open this script self.__apiContext:open(scriptId)