Why is game:IsLoaded() not working?

image
It is printing false always and not changing, the game is just a baseplate…

this code is in a local script in replicated storage right? if it is then I don’t know how to help, but remember that:

Unless they are parented to ReplicatedFirst , LocalScripts will not run while the game has not loaded.
https://developer.roblox.com/en-us/api-reference/function/DataModel/IsLoaded

4 Likes

It is a script in ServerScriptService.

game:IsLoaded is supposed to be used in a localscript

4 Likes

They cannot be ran on the server from what I know.
When I tried it just caused a bunch of lag.
Put it in a Client Script in ReplicatedFirst.
I don’t know what you’re trying to make with this, but if it’s something like waiting for a character to fully load in, just do something like:

game.Players.PlayerAdded:Connect(function(p)

repeat wait() until p.Character

-- Rest of the code here

end)
1 Like

Yeah, please read the documentation.

This function returns true if the client has finished loading the game for the first time.

ServerScriptService is a container for Scripts. Scripts represent the server. The value returned by IsLoaded does not replicate across the client/server boundary.

For both OP and @Fluffy_OnYT, events exist so please use those instead. If event-based programming is staring at you in the face you should try and avoid polling with repeat/while loops. Your code will wait more time than is actually necessary rather than executing as in when it needs to.

-- In the case of Loaded:
if not game:IsLoaded() then game.Loaded:Wait() end

-- In the case of characters:
if not player.Character then player.CharacterAdded:Wait() end
5 Likes