In the game, you can buy businesses and place them on slots on your plot. Once bought, you can click on these businesses and after a certain amount of time, you gain money and you can click the business again to earn more money.
Business usage is handled through a remote event, where the business’s name is fired to the server. When the server receives the remote event, the level of the business and the boosts from the player is then used to calculate the amount of cash to give to the player, which is done by changing a value object under the player’s Player instance. One of the boosts that is taken into account is a gamepass that doubles profit. This is where UserOwnsGamePassAsync is used.
There is another feature called “Managers”, which automatically uses the business it is specific to automatically. When a business called “Lemon stand” is upgraded to over level 300, the cooldown is 0s, and when the Lemon stand manager is active, the use business remote event is fired every .Heartbeat:Wait(). I know this should be reworked, but this is the last update I’m going to be working on for this game and I’ll be working on other things.
Now you can see why I was using UserOwnsGamePassAsync every frame. Once I realised that, I fixed it by adding a cache system. It’s quite simple. When a player’s gamepass ownership is first checked, UserOwnsGamePassAsync is called and it is stored in a table. Thereafter, any further checks for ownership would return the value stored in the table. When a player buys a gamepass, their cache is updated. When the player leaves, their cache is removed from the table. I thoroughly tested this and made sure that it’s working perfectly fine, but the issue is still happening. I’ll be taking another look at the scripts to make sure I didn’t miss anything, and to find possible fixes.