Pcall throws an error?

I’m trying to rebind the reset button of the player. Usually the script works fine, but now it’s started erroring out of seemingly nowhere, despite wrapping it in a pcall.

Code: (I know it’s not the best way to do it but bear with me)


local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")

local ResetRemote = ReplicatedStorage.Remotes.OnPlayerReset
local ResetBindable = Instance.new("BindableEvent")


local isRegistered: boolean = false

while not isRegistered do
	isRegistered = pcall(StarterGui.SetCore, StarterGui, "ResetButtonCallback", ResetBindable) --This line errors

This code works for me. Maybe there was a desync of some sort? Try adding a print to see if anything changes.

The items in SetCore aren’t guaranteed to exist at all, so the next best thing is to poll for them.

local function CoreCall(Name: string, TimeOut: number, ...: any): boolean
	local TimeElapsed: number = 0
	while true do
		local Success: boolean = pcall(StarterGui.SetCore, StarterGui, Name, ...)
		TimeElapsed += task.wait()
		if Success or TimeElapsed > TimeOut then
			return Success

-- Since it can actually not ever exist
-- You should always failsafe your code if it never appears
local Passed: boolean = CoreCall("ResetButtonCallback", 5, Bindable)

I’m not exactly sure why your pcall is failing, but for my studio session it seems to work fine.

Apparently now it works fine??? Don’t know exactly what went wrong here or why.

What do you mean by desync?
I had added a print("Registering") before the line with the pcall and it just printed once before erroring.

Sometimes script edits don’t get applied properly, and you have to make another change. If you were able to print again, something else is going on.

1 Like

UPDATE: This issue only happens in Roblox Studio if the “Debugger Enabled” setting is enabled. Otherwise it works as expected.

I could just disable the setting, but the problem is that if I turn it off, many useful features of the script editor disappear (such as breakpoints and hovering over a variable to see its type). If this is a bug, should I submit a bug report?