BindToClose or Close?

-- Hi!
-- What should I use?

-- Close:

game.Close:Connect(function()

end)

-- (Deprecated) OnClose:
game.OnClose = function()

end

-- BindToClose:

game:BindToClose(function()

end)

If .Close is deprecated, use BindToClose,

OnClose is Deprecated, not Close.

Oh.
Well, either way, I can’t find Close on the page for DataModel (aka the actual class of game), so I’d use :BindToClose() either way.
Link: DataModel | Roblox Creator Documentation

Close Method
Its Under “Inherited from ServiceProvider”

Ohhhhh so that’s why I didn’t see it.
I don’t think it matters which one you use, I personally use :BindToClose() as that’s what I am familiar with using.

1 Like

I’ve rarely seen game.Close being used, actually, it’s the first time I heard of it. It seems like game.Close and game:BindToClose() have the same functionality. One is simply an event that you can connect to and the other is a method.

I’d recommend you use game:BindToClose(), not because it’s better, but it’s because the more known version of it. In case any other developer reads your code, they should be familiar with game:BindToClose().

You can ignore the other way. If something is deprecated, you should refrain from using it at all.

1 Like

After further inspection, it seems that game.Close does not allow you to yield inside of the function connected to it. For that reason, and especially when saving player data, it would be detrimental to use game.Close. To be safe, use game:BindToClose() - that will work for sure, even in the case you yield.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.