How to know when Profile Service is ready?

Hello guys, I have made a small module based on the Profiler service because I prefer function names like “get data”, here is a function I used to get the value of some key:

But I have encountered a problem. When the first player is added to the game, the profile service is most likely not ready:

I have tried tackling this problem by using a while loop:
image

However, I don’t think it’s the only solution. Do you guys have any good ideas?

1 Like
repeat task.wait() until PlayerServerClass:GetIns(player):GetOneData(dataKey.power1)

Thank you! But it’s still a loop, and I prefer not to wait for something using a loop.

In Roblox, the usual way to wait for something is by using the following methods:

  • Players.PlayerAdded:Wait()
  • part.Changed:Wait()

Maybe I have come up with a good idea :grinning:.

The best way to go about doing something like this is actually a for loop since :Wait() is available only using native methods of services. Since we’re waiting for an Instance modulary, a repeat loop would serve the best use. Good news is, it disconnects once the condition is met.

1 Like

I’m almost certain this is a bad idea. calling the api that fast is just asking for errors.

@M78zhaoritian the best way to fix your issue is to modularize your code and initialize profile service before anything else. It will prevent race conditions.

2 Likes

Thank you, friend. However, I’m facing difficulties in initializing the profile service before anything else in my code. Even when I try to require it at the very beginning, there still seems to be some delay in handling players’ data. Could you provide a little details ?

1 Like