Unable to Invoke a BindableFunction from the invoke handler of another BindableFunction

The engine throws an error if you try to invoke a BindableFunction from the invoke handler of another BindableFunction.

Sample use case:
I have build a confirm modal that have multiple bindable functions, see:

image

The thought is to assign YesButtonFunction and NoButtonFunction to a function so you can do the operations you want when respective button is clicked. Then you should invoke the HideModal function.

Example code:

deleteButton.Activated:Connect(function() 	
	confirmModalGui.ModalTitleText.Value = "Delete pet?"
	confirmModalGui.ModalBodyText.Value = "You are about to delete " .. selectedPet:GetFullName() .. ".\n\nAre you sure you want to do this?"
	
	confirmModalGui.YesButtonFunction.OnInvoke = function()
		print("Delete pet")
		confirmModalGui.HideModal:Invoke()
	end
	
	confirmModalGui.NoButtonFunction.OnInvoke = function()
		confirmModalGui.HideModal:Invoke()
	end

	confirmModalGui.ShowModal:Invoke()
end)

This results in an error being thrown:
13:38:59.938 - cannot resume non-suspended coroutine

13:38:59.939 - Stack Begin

[13:38:59.940 - Script 'Players.SamSwifthoof.PlayerGui.ConfirmModalGui.ConfirmModalScript', Line 33](rbxopenscript://www.dummy.com/dummy?scriptGuid=%7B469b29fa%2D15b7%2D4c2b%2Dbce0%2Db184115cf98c%7D&gst=2#33)

13:38:59.940 - Stack End

I have checked that each BindableFunction is working when being invoked separately, but the error is being thrown if you invoke HideModal from another BindableFunction handler.

Steps to reproduce:

  1. Add BindableFunction1 and BindableFunction2
  2. Invoke BindableFunction2 from the handler of BindableFunction1

Expected results: BindableFunction2 OnInvoke should be called

Actual results: The coroutine error is thrown

3 Likes

Please provide the exact code you are using or a simplified repro of the issue. I was unable to replicate this issue with the following code:

local bindable0 = Instance.new("BindableFunction")
local bindable1 = Instance.new("BindableFunction")

function bindable0.OnInvoke()
	print("Bindable0 Invoked")
	bindable1:Invoke()
end

function bindable1.OnInvoke()
	print("Bindable1 Invoked")
end

bindable0:Invoke()

Output:

> Bindable0 Invoked
> Bindable1 Invoked
1 Like

I am sorry - it was not related to only the BindableFunctions. It was related to that the ImageButton fired Activated twice (for some reason) that caused BindableFunction invoke to be called twice which caused it to misbehave.

Adding a debouce on the ImageButton Activated handler mitigated this.

Tried to create a clean reproduction case for this, but I guess you can close the thread (if there is such a function)

For reference the full call chain looked something like:

imageButton.Activated:Connect(function()
	bindable0.Invoke()
end)

function bindable0.OnInvoke()
	print("Bindable0 Invoked")
	bindable1:Invoke()
end

function bindable1.OnInvoke()
	print("Bindable1 Invoked")
    -- hide a gui
end
1 Like

Again, I was unable to reproduce it using this code:

local bindable0 = Instance.new("BindableFunction")
local bindable1 = Instance.new("BindableFunction")

button.Activated:Connect(function ()
	print("Button Activated")
	bindable0:Invoke()
end)

function bindable0.OnInvoke()
	print("Bindable0 Invoked")
	bindable1:Invoke()
end

function bindable1.OnInvoke()
	print("Bindable1 Invoked")
end

Output:

> Button Activated
> Bindable0 Invoked
> Bindable1 Invoked

I’m not quite sure what was happening, but it sounds like you’ve fixed it. If you do run into it again, drop a reply here with a way for me to reproduce it and I’ll take a closer look :slight_smile:

2 Likes