BindableEvent not working occasionally

I have this script that runs once for each character in my game. (RegisterCharacter is a BindableEvent)

game.ReplicatedStorage:WaitForChild("RegisterCharacter"):Fire(script.Parent)

In practice, the BindableEvent doesn’t fire about half the time. Adding a wait before running the above line of code resolves the issue, but I’m not satisfied with that solution. Does anyone know why this code is breaking, and what it is that the script needs to wait for?

1 Like

If just a Wait fixes it, it might be the fact that script.Parent in :Fire() is nil. Is this a localscript or script?

1 Like

I’ll add a print to test if that’s the issue, and it’s a script.

1 Like

You sure you also checked the devconsole? Might be a error.

1 Like

I checked again, there’s no error.
I also added the following line of code at the beginning of this script:

print(script.Parent.Name)

The correct names appear in the output, but the same issue is still present.

add a print to the beginning of the bindable event function and see if that fires before anything else within it.

Seems to work fine for me, must be a issue in your bindableevent.

Sorry, could you explain what you mean by “bindable event function?”

check to see if that print at the beginning fires first before anything below it.

local function event()
	warn(1)
end

be.Event:Connect(event)

if it fires at different times, then your issue might be within that function or before it, otherwise i couldn’t really tell you what it exactly is since information is vague.

1 Like

I figured the problem out. The problem is that the BindableEvent is firing before a different script can connect a function to it. However, I don’t really know how to fix that aside from just adding a wait. Anyone know how to fix that?

2 Likes