Telling when data is fully loaded

So I’ve noticed that when I load in data, for example, one value I save are levels. When a player joins the game and their level was 16, the data loads in increments. I printed the level every time it changed when the player joins. It would print random numbers, but the output shows: Level: 3, Level: 9, level: 13, Level: 16. It would stop until it was fully loaded. Not sure if that’s how Roblox loads in their data. If so, is there a way I can tell when the player’s data is fully loaded?

1 Like

As far as I know, the most effective way to manage this kind of issue is just doing a wait() for maybe around 2-5 seconds to prevent errors or issues from occurring.

Code smell. Don’t.

I’ve never seen this behaviour before in terms of the level value being loaded incrementally. There’s no code or implementation details so I don’t know whether this is just a strange way Roblox loads data or if there’s something up with your implementation, but try implementing a BindableEvent.

After all your data set operations (e.g. if you have a dictionary for player data, then after the for loop that traverses the dictionary), consider firing a BindableEvent and setting a flag of some kind. Another script can then check this flag or wait for the BindableEvent to fire. Mimics the deprecated DataReady feature.

3 Likes

At this moment I encountered the same problem. I programmatically build maze-levels for a game I work on. Once a maze is built, I put the main character there. In studio everything is OK, but if a game is played via app, then a character FALLS DOWN NOWHERE, just because under his feet there is no floor. The floor is a part of the maze of course…

I tried a few methods, the only effective was just to use wait() :rofl:
But I found a smart-wait method. Here is my solution which you can apply in your project.

when a maze was build, the very last added part got a name “the_last_part”
a_part.Name = "the_last_part"

All you need is to detect it via a line which for my project looks lie this:

local the_last_block = workspace:WaitForChild("Level_Group"):WaitForChild("the_last_item")

The line above MUST BE in a local script. So I created an event that fires a client’s function which detects if “the_last_part” is loaded and when it finds it, then it fires the server back, so the server continues to do what ever is designed. I hope you will figure out how to do it in your specific project. Just in case I will show my code:

Lines from the server script

local Continue_loading_event = Instance.new("RemoteEvent", ReplicatedStorage)
Continue_loading_event.Name = "Continue_loading_event"
--
--
--
-- server event
Continue_loading_event.OnServerEvent:Connect(_G.Load_Level_CONT_sub)

Lines from local script

ReplicatedStorage = game:GetService("ReplicatedStorage")
    local Continue_loading_event = ReplicatedStorage:WaitForChild("Continue_loading_event")
    --
    --
    --
    local function last_part_event_sub()
        print("Client received it")
        local the_last_block = workspace:WaitForChild("Level_Group"):WaitForChild("the_last_item")
        print("And fires back")
        Continue_loading_event:FireServer()
    end
    --
    --
last_part_event.OnClientEvent:Connect(last_part_event_sub)

All you have to do is to trigger the whole sequence from the server using this line:

ast_part_event:FireClient(The_Player)
print("Client fired")

– Just in case you do not know what The_Player var is:

Players_OBJ.PlayerAdded:Connect(function(an_obj)
	The_Player = an_obj
end