Script does not fire bindable event, but no errors

  1. What do you want to achieve? Keep it simple and clear!
    I want my script to fire another script with a bindable event. Both of the scripts are normal “Script”
  2. What is the issue? Include screenshots / videos if possible!
    I have a print under the :Fire() line, and it prints “Fired other script”, so it must have “read” the :Fire() line. But, the print on the other script that i tried to fire doesnt print anything.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Yes.

Script:

Script 1: 

if gameInProgress == false then

votingScriptEvent:Fire()

print("fired other script") --this prints!!

end


Script 2: 

votingScriptEvent.Event:Connect(function()

print("GOT REQUEST") --does not print.... 

--mapsAlreadyChosen = {}

getRandomMap()

end)

I have no idea why…

ANSWER:
Thank you kinkocat for your answer.

I turns out my script didnt connect to the bindable event in time, fixed it by adding wait(1) infront of the if statement.

1 Like

Are both your scripts located on the server or client? They must be in either the client or the server; bindable events are not capable of client-server communication. If you want to achieve that you’d need to use remotes.

2 Likes
votingScriptEvent:Fire()

Should be:

votingScriptEvent:FireServer()

votingScriptEvent.Event:Connect(function()

Should Be:

votingScriptEvent.OnServerEvent:Connect(function()

Hope this helps.

@K_ngTMB

Both scripts are located on the server. And use BINDABLE EVENTS. Not REMOTE EVENTS.

No, he has it setup correct and from the looks of it he isn’t trying to cross the client server boundary. He said both are utilizing a normal “script”

1 Like

Are you somehow initializing the event AFTER you are firing the event?

1 Like

What do you mean by that?

(ignore i just need more than 30 digits)

If you are firing the event before you connect the event to a function it will still fire properly but the function you connected it to won’t.

Bindable:Fire()

Bindable.Event:Connect(function()
       -- This won't fire beacuse the event was fired before this function was connected.
end)
1 Like

No I do not think so.
These code snippets are located in different scripts.

Just to make sure you understand his question, make sure that you do not have any yielding code above the .Connect()

1 Like

I got this code above the .Connect()

votingScriptEvent = script.StartVotingScriptEvent
mapFolderNames = game.Workspace.Maps

function getRandomMap()

	local mapFolderContentsArray = mapFolderNames:GetChildren()
	local randomMapChosenIndex = math.random(1, #mapFolderContentsArray)
	local randomMapChosenName = mapFolderContentsArray[randomMapChosenIndex]
	print(randomMapChosenName)
	return randomMapChosenName
	
end

Edit: I doubt this yields it…

I noticed in the above code that the event you are trying to connect is a child of the connecting script.

Is the script with the :Fire() calling on the same bindable event instance?

1 Like

Yes, I believe so.

votingScriptEvent = game.Workspace.MainScripts.VotingScript.StartVotingScriptEvent

That doesn’t yield but my point is that the event could still be firing before the function is connected to the event. If i were you i would yield the script that fires the event for a second prior to the event being fired to test this.

Script 1

wait(1)
Bindable:Fire()
print("This should print second")

Script 2

print("This should print first")
Bindable.Event:Connect(function() -- This should initizialize first now since you are telling the other script to yield.
     print("Fired")
end)

Your logic isn’t incorrect here and this is really the only thing that i can think of unless you unknowingly have one of your scripts disabled or something like that.

Script 2 printed first sadly… Hmmm.
I have no idea what to do now…

Do you have a place file that could be looked at, this is strange? You could PM it if you want.

Sure. Sending it now!
I simplified the code a lot, just so the “problem” parts get shown. Still doesnt work…

@K_ngTMB metryy
(Edit: Sorry! Misread your post.)

Make sure you read the thread and understand what it’s asking for before replying. Attempting to use Fire on a RemoteEvent would result in an error due to attempting to call a nil method. OP mentioned that they are using BindableEvents and that there are no errors appearing.

I recognise this was mentioned earlier but I felt it would be best to provide feedback and resources regarding both objects for your research needs.

1 Like

Why did you tag me? I never suggested calling fire on remotes. I asked him if his scripts are both located within either the server or the client.

1 Like

Might be my fault, he looked at the people I tagged in my response. And I tagged you by accident. Sorry