Bindable Event Only working in one script location?

Have a function that Fires a bindable event. Which you can see below.

PrivateLeave1.OnServerEvent:Connect(function(player)
	local String = player.Name
	local PlayerTeam = PPlayerTeam1
	local PPlayer1 = PP1Player1
	local PPlayer2 = PP1Player2
	local PPlayer3 = PP1Player3
	local PPlayer4 = PP1Player4
	player.Team = NoParty
	for i, name in pairs(PPlayerTeam1) do
		if name == String then
			table.remove(PPlayerTeam1, i)
			if i == 1 then
				PP1Player1.Value = "Player 1"
				PP1Player2.Value = "Player 2"
				PP1Player3.Value = "Player 3"
				PP1Player4.Value = "Player 4"
				GuiReset:Fire(PlayerTeam, PPlayer1, PPlayer2, PPlayer3, PPlayer4)  --bindable event
				break
                        end
                 end
       end
end)

This Bindable Event works with multiple functions which is the purpose for the local variables below.
To pass different team values which includes the players.

There is nothing wrong with the code above, I moved this function into the same script for the function for the bindableevent (GuiReset). Both scripts are Server Scripts.

I thought bindable events are supposed to work with separate server scripts?
Error I get is "attempt to index function with ā€˜Fire’
What’s the reason for this error and what is it saying?

The error you’re getting is saying that you’re trying to call Fire from nil (see below), meaning that GuiReset is pointing towards a nil object function. You have the right understanding of BindableEvents but not the source of your error which is that the variable itself is nil the wrong type.

4 Likes

The error says ā€œattempt to index function with ā€˜Fireā€™ā€, not ā€œattempt to index nil with ā€˜Fireā€™ā€, meaning that the GuiReset is defined as a function

@OP: As mentioned before, GuiReset is defined as a function somewhere in your code. You should show your definition or consider different naming

3 Likes

:tired_face:

That’s my bad, I glazed over the error message - thanks for the correction lol.

3 Likes

Got it, thanks for the clarification! Problem solved.