From d13918926aa2ffa7b95467197e4a5e212f301f83 Mon Sep 17 00:00:00 2001 From: Kenneth Loeffler Date: Sun, 22 Sep 2024 17:19:21 -0700 Subject: [PATCH] Wait for game.Name to change before running rbx-reflector plugin (#449) --- rbx_reflector/plugin.lua | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/rbx_reflector/plugin.lua b/rbx_reflector/plugin.lua index 21d6b3ad7..4002e22e8 100644 --- a/rbx_reflector/plugin.lua +++ b/rbx_reflector/plugin.lua @@ -1,4 +1,32 @@ -if game.Name ~= "defaults-place.rbxlx" then +local function isDefaultsPlace() + -- After https://devforum.roblox.com/t/place-open-improvements-test/3086811, game.Name + -- is no longer immediately equal to its value defined in a place file after opening a + -- place file. Rather, game.Name is set the value defined in a place sometime after + -- the place is opened. We need to wait for game.Name to change before validating that + -- the place file in which this plugin is running is correct. + + -- Since if or when game.Name changes seems to be an implementation detail, we + -- shouldn't assume game.Name will ever change. So, we'll wait for game.Name to + -- change, or else wait out a two second timeout, whichever comes first. + local didGameNameChange = false + local timeElapsed = 0 + + game:GetPropertyChangedSignal("Name"):Connect(function() + didGameNameChange = true + end) + + while not didGameNameChange and timeElapsed <= 2 do + timeElapsed += task.wait() + end + + if game.Name ~= "defaults-place.rbxlx" then + return false + end + + return true +end + +if not isDefaultsPlace() then return end