Referencing an object, but I don't know if it exists yet

I am writing a script that is client side, that runs a remote function that returns a table. The problem is that the remote function if firing before everything in serverscriptservice is loaded. On the server side I need to reference something in serverscriptservice, sometimes it happens to work other times I get an error saying the object doesnt exist is there a way to make the local script wait until serverscriptservice if fully loaded.

Ive tried β†’

local object = game.ServerScriptService:FindFirstChild('object that i need')

Ive also tried β†’

local object = game.ServerScriptService:WaitForChild('object that i need')

and both–>

local object = game.ServerScriptService:WaitForChild('Object that i need') or game.ServerScriptService:FindFirstChild('object that i need')

Anyone know a way I can reference this object, or a way of making the client or server side scripts wait until serverscriptservice if fully loaded??

1 Like

if game.ServerScriptService:WaitForChild("obj that you need") ~= nil then -- code here end

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