BindToClose does not work on Team Create with plugins or the command bar

Reproduction Steps
By creating a plugin or running game:BindToClose through the command bar, an error will be thrown stating that it can only be ran from the server.

Sample code that will throw this, can be used in both a plugin or the command bar:

game:BindToClose(function() end)

Expected Behavior
I expect it to work. It works in non-team-create places and is essential to a key plugin I’m developing for my team’s workflow.

Actual Behavior
An error is thrown.

  18:25:40.384  BindToClose can only be called on the server.  -  Edit
  18:25:40.384  Stack Begin  -  Studio
  18:25:40.384  Script 'game:BindToClose(function() end)', Line 1  -  Studio
  18:25:40.384  Stack End  -  Studio

Issue Area: Studio
Issue Type: Other
Impact: High
Frequency: Constantly

6 Likes

Out of curiosity, what is the workflow in question? Because even if it did work, it’s not 100% reliable, if Studio crashes (for instance due to some plugin running an infinite loop by accident) then you won’t get the OnClose, so you have to be prepared for a scenario where that happens.

4 Likes

We’re trying to establish a studio time and changes tracker for development sessions (this is a plugin for the development team) that is capable of sending those through HttpService when studio is closed during edit mode. You bring a fair point with crashing, but that is something that we can try work around similarly
to the current “work around” (currently the data updates and saves to a setting every 5 seconds and is retransmitted on request since BindToClose does not work on team create sessions); however, having BindToClose functional in team create would allow us to have the data sent and the setting cleared (considered “sent”) as soon as studio closes successfully, avoiding the trouble of having to manually send it back when a session restarts every time. (and quite simply much easier as there is no problem about forgetting to send it or having to click somewhere to clear and send the current session)

2 Likes

Thanks for the report! I’ve filed a ticket to take a look into this.

In the meantime, could the Plugin.Unloading signal work for you?

3 Likes

I’ve tried using Plugin.Unloading, but unfortunately it does not fire when the place or studio are closed. I guess it could suffice for plugin disabling, updating or uninstalls, but it currently doesn’t for closing. I’m unsure if this is a bug (?) since on the DevHub it doesn’t state this as intended; Plugins are unloaded when disabled, uninstalled, about to be updated, or when the place is closing.

but it currently doesn’t for closing

Do you have a repro for this? Trying it locally with a simple plugin (just `plugin.Unloading:Connect(function() print("Unloading!") end)` ) seems to work for me when closing both local places and team create places.

So I investigated further and found out the issue is not in Unloading (oops :sweat_smile:) but rather in the fact I was trying to make a http post request on the unload, and since I was saving it as a Local Plugin to test, it was removing the previously granted http permission. If I grant it beforehand it works. Thanks!

1 Like

Thank you for submitting this report. We are currently reviewing all bug reports to ensure we have not overlooked any ongoing issues. Since this issue was reported over two years ago, can you please confirm you are still experiencing the problem? If so, please respond to this thread, and we will investigate. If we do not receive any response within 30 days, we will consider this matter resolved. Thank you.