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)
--!strict
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")
local ResetRemote = ReplicatedStorage.Remotes.OnPlayerReset
local ResetBindable = Instance.new("BindableEvent")
ResetBindable.Event:Connect(function()
ResetRemote:FireServer()
end)
local isRegistered: boolean = false
while not isRegistered do
isRegistered = pcall(StarterGui.SetCore, StarterGui, "ResetButtonCallback", ResetBindable) --This line errors
task.wait()
end
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
end
end
end
-- 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.
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?