Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Best way to load things from _G?

Asked by 9 years ago

So I'm trying to store a table in _G, for all of my other server scripts to access. The only problem I'm having here is at the beginning of every other server script, this code is pretty much required to access _G.ServerData

while not _G.ServerData do
    wait()
end

So I know why this is needed, however it gets kind of tedious to keep pasting this at the beginning of every new script I make.

Question

With that out of the way, this is basically my question: Is there a way to guarantee that _G.ServerData will always be ready to access without having to write the same code above in every script?

Is there like a service or something I can put server scripts into to guarantee they'll run first? (like the ReplicatedFirst service, but for server scripts)

Anyway, if anybody has some insight on this I'd appreciate it. Thanks.

1 answer

Log in to vote
0
Answered by
RafDev 109
9 years ago

I'm afraid there isn't a way to do that, or any service you can access like ReplicatedFirst, but for Server Scripts. There are some other ways to do what you're doing, though. I recommend method one because it's much more easier for me, but it's your choice.

METHOD ONE - CLEANING

To make it much more easier, instead of pasting all that, you could just type repeat wait() until _G.ServerData at the beginning of your Server Scripts.

METHOD TWO - TOGGLING SCRIPTS

You can also have all the scripts in ServerScriptService, disabled, and have this after you set _G.ServerData:

for _,s in pairs(game:GetService("ServerScriptService"):children()) do
pcall(function() s.Disabled=false end)
end

Hope it helps! :)

Ad

Answer this question