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”
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.
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.
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.
function getRandomMap()
local mapFolderContentsArray = mapFolderNames:GetChildren()
local randomMapChosenIndex = math.random(1, #mapFolderContentsArray)
local randomMapChosenName = mapFolderContentsArray[randomMapChosenIndex]
print(randomMapChosenName)
return randomMapChosenName
end
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.
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.