Data loading event

Hi! I have a datastore in my game but I want to make it that it fires an event when it finishes loading so a few other scripts doesn’t start before the data loads. Here is what I have for now:

-- Datastore script hidden above.
print("loaded")
local loadedData = Instance.new("BindableEvent")
loadedData.Name = "LoadedData"
loadedData.Parent = game:GetService("ServerScriptService")
loadedData:Fire()
print("fired")

And here is my script that I don’t want to run before the data loads:

local loadedData = game:GetService("ServerScriptService"):WaitForChild("LoadedData")

game.Players.PlayerAdded:Connect(function(player)
	loadedData.Event:Wait()
	
	print("Script waited successfully")
	-- Rest of the script hidden
end)

I only get "loaded" and "fired" in my output but not “script waited successfully”. I don’t understand what is wrong with my script, please help.

Your script is pretty weird. It seems like when you are done loading the player’s data, you would create a new BindableEvent instance and parent it to under a service everytime a player joins the game. And since you are only referring that one particular BindableEvent and nothing else, it will break eventually.

You should reconstruct the script such that you could make a function out of the second script and use it in the DataStore script.

1 Like

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