This is in a LocalScript inside StarterPlayerScripts. When I join the game, nothing happens. No errors in Console. This is all that is in the script too.
copy-pasted that code in a new place and it works as expected to
on another note, you won’t see any errors coming from inside the pcall
instead, it returns whether it ran successfully or not, and if that is false, then it also returns an error message
you could try printing the pcalled function and see if it works fine
here’s the documentation for pcall: http://robloxdev.com/articles/Built-in-Functions-and-Variables/Lua#pcall
Still doesn’t work works when I play solo, but not on a real game. If I add time to the wait then it does work, but I don’t want players to just see the topbar disappear
This is because the StarterGui may take a bit to load in, try using
repeat wait until game:IsLoaded()
at the beginning of the script.
This will still give you the same issue (most likely) where the top bar kind of disappears but as of right now I am unsure about another way.
Quickly had a look through previous devforum posts, found a solution by @Fractality_alt which is working fine. Can be found here.
-- Disable the topbar asap
coroutine.wrap(function()
local timeout = 1
local t = tick()
while not pcall(game.StarterGui.SetCore, game.StarterGui, 'TopbarEnabled', false) and tick() - t < timeout do
wait()
end
end)()