Bindable Functions not returing at right context

I’m trying to create a verification screen, to make sure if a player would like to start a paid job
I have a separate script for screen creation and text manipulation, so for that, I use a bindable function to communicate between the client so I don’t have to create the same function several times

First Script:


AreYouSureBF.OnInvoke = function(context,message)
	print(context,message) -- Output: Work, nil (second par. doesn't matter)
	AreYouSureFrame.Visible = true

...
elseif context == "Work" then
		
		AreYouSureFrame.AreYouSureText.Text = "Are You sure you want to Work at Home Improvement as a Boxer?"
		
		AreYouSureFrame.Confirm.MouseButton1Click:Connect(function()
			print("click")
			
			return true
		end)
	end

Second one:


game.ProximityPromptService.PromptTriggered:Connect(function(prompt,trPlayer)
	
	if prompt.Name == "Boxer" then
		local SureToWork = AreYouSureBF:Invoke("Work")
		
		if SureToWork == true then
			print("Sure")
		end
		
		print(SureToWork)
	end
end)

the problem is that, as soon as I click on the proximity prompt, the output returns nil and does not follow the constructor, where it would only return true if I clicked on the “YES” button

image

When you are returning true in the MouseButton1Click event, it’s not working the way you want. It’s returning in the event, not the bindable function.

1 Like

i tried to create a condition that returns outside the event, but that didn’t work either

Try this:

AreYouSureBF.OnInvoke = function(context,message)
	AreYouSureFrame.Visible = true
	if context == ? then
		-- ?
	elseif context == "Work" then	
		AreYouSureFrame.AreYouSureText.Text = "Are You sure you want to Work at Home Improvement as a Boxer?"
		
		AreYouSureFrame.Confirm.MouseButton1Click:Wait()
		return true
	end
end

The value is returned to the RBXScriptConnection that comes from MouseButton1Click:Connect, not your BindableFunction. You don’t get values when you return in a connection.

You’ll want to fix this by writing your code in a different way overall. There’s a couple of ways you can go about changing this including up to changing the overall code structure you have which is what I’d personally recommend. I don’t think you want a BindableFunction here.

My personal advice would be to look into using ModuleScripts here. For the logic you don’t want to rewrite over, you can write a parametrisable function.

2 Likes

this worked but like @colbert2677 said, i’ll have to change some things in my code, thanks a lot everyone!

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