How do I guarantee CoreGui will be reloaded

I cannot figure out how to successfully guarantee the core gui is removed.

ReplicatedFirst.Loading:39: SetCore: ResetButtonCallback has not been registered by the CoreScripts

I mean, I can keep adding retries, but it shouldn’t take 8 tries in the first place :face_with_raised_eyebrow:

local CoreCall do
	local MAX_RETRIES = 8
	
	local RunService = game:GetService("RunService")
	local StarterGui = game:GetService("StarterGui")
	
	function CoreCall(method, ...)
		local Result = {}
		for retries = 1, MAX_RETRIES do
			Result = {pcall(StarterGui[method], StarterGui, ...)}
			if Result[1] then break end
			
			task.wait(0.5)
		end
		
		return unpack(Result)
	end
end

assert(CoreCall("SetCore", "ResetButtonCallback", false))

while not Success do
	Success = pcall(function()
		StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
	end)
	
	task.wait(1)
end

1 Like

You need to wait for the CoreScripts to register, I believe it should work after game.Loaded has fired.

1 Like

Sorry, I didn’t include the entire script. I do wait for the game to load above this tho

1 Like

Don’t see the need for such a complex function?

function coreCall(method, ...)
  local MAX_ATTEMPTS = 5
  local attemptCount = 0

  local fired, result
  repeat
    fired, result = pcall(StarterGui[method], StarterGui, ...)
    attemptCount += 1
    task.wait(1)
  until fired or attemptCount > MAX_ATTEMPTS
end

I wrote this just now so it might be wrong

1 Like

game.Loaded is an event, it is always present. You need to check for game.IsLoaded.

1 Like

It’s simple: While this error is unavioudable, there are some fixes to it.

You can make a loop to register it, such as this:

repeat
    task.wait()
until game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.All, false)

Alternatively, you could just teleport the player to a new server instance if it’s not registered. These are the two most efficient ways to do it which I found. Anyway, cheers! :grinning:

The error in the OP is specific to SetCore. SetCoreGuiEnabled does not produce this error because they accept initial state from scripts as well as configuration later during run time. Even then, you should not be using a repeat loop here because your code may end up waiting one iteration unnecessarily if it’s already able to be executed immediately.

Registration occurs as CoreScripts are executed and set up the backend for the relevant option. Teleporting players to a new server has no bearing on registration and is a poor non-solution.

1 Like

Did this and I still get errors every so often saying it hasn’t been assigned yet :confused:

Why are you waiting for game.Loaded? You could wrap it in a call and keep attempting to disable it.

1 Like