I need help with bindable events

Hi there !
I am trying to use bindable event to tell a script to load a map, then that map loader will fire it back to tell the first script that it has finished loading the map.
Sadly, i can only fire it one way. I can tell the map loader to fire the event, but when i try to fire it back, it just does not fire. (No errors or anything)

Here is the first script:

local MapLoaded = false

local function FilterFunction(Recipient)
	if Recipient == "MapLoaded" then
		MapLoaded = true
		wait(1)
		MapLoaded = false
	end
end

GameLoopBindable:Fire("LoadMap")
repeat wait() until MapLoaded == true
--Continue the script

GameLoopBindable.Event:Connect(FilterFunction)

And here is the map loader script:

local function LoadMap()
	print("Would load map")
	--Load map here
	GameLoopBindable:Fire("MapLoaded")
end

local function FilterFunction(Recipient, Argument1)
	if Recipient == "LoadMap" then
		LoadMap()
	end
end

GameLoopBindable.Event:Connect(FilterFunction)

Thanks for your help!!

1 Like

Avoid using the same BindableEvent instance for 2 separate events.

1 Like

is there a way to do use the same ?
it would make my script 1000 times simpler…

1 Like

You don’t even need to use a BindableEvent for this. You could combine the two server scripts into one.

2 Likes

hey thats a good idea !!
im just going to do a load map function and call it instead…

Thank you so much!!

1 Like

No problem, also I believe this was your issue.

repeat wait() until MapLoaded == true
--Continue the script

GameLoopBindable.Event:Connect(FilterFunction)

The function wasn’t being connected to the event until after the repeat until loop completed (it never completes).

1 Like

Oh. Thanks for your help!!
I will still use only one script, I really liked that idea !!

1 Like

Wouldn’t bindable function work too? Its specifically designed for 2 way communication.

2 Likes