SetCoreGuiEnabled works in studio but not in game

I have this function (in a module script) which seems to work perfectly in studio but in an actual game the coregui can be disabled through this function but whenever I try enable it again it does not work

function UiUtil.SetCoreUi(enabled : boolean)
	spawn(function()
		local timeout = 5
		local t = tick()
		local success, err = pcall(function()
			StarterGui:SetCoreGuiEnabled('All', false)
			if enabled then
				StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
				StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, true)
				StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, true)
			end
		end)
		while not success and tick() - t < timeout do
			task.wait()
		end
	end)
end

Have you tried printing out the error?

Also if you disable all of coregui it will disable everything until you set it to be enabled again so you would need to set all the other cores to be false instead

No errors are printed. Even when I do the following (constantly trying to enable the core gui) it is not enabled while playing in game although works fine in studio.

while true do
   task.wait(1)
    StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
end

Why are you looping over it if it isn’t a success? It will return if it’s a success or not so if it isn’t just call the function again instead of a while loop

Have you published the changes in Studio?

Why use a spawn and pcall for this … It’s just a normal call.

local StarterGui = game:GetService(“StarterGui”)
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)

This also only works in a local script.

You need a pcall incase you call SetCoreGui before the core gui is loaded. And the spawn just makes it so I dont have to wait for the core gui to load while doing other stuff.

And it also isn’t working outside the studio … Mine seems to work fine without all that.

ive fixed it. There was another script that disabled the core GUI when the game starts and somehow that effected my script which doesnt really make sense.

I was just giving you advice.

need more characters

“I was just giving you advice. need more characters”
? … ok

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