@K_ngTMB
Both scripts are located on the server. And use BINDABLE EVENTS. Not REMOTE EVENTS.
@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”
Are you somehow initializing the event AFTER you are firing the event?
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)
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()
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?
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.
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.
Might be my fault, he looked at the people I tagged in my response. And I tagged you by accident. Sorry
Solution found, for those who might visit the thread after with a similar issue the problem was OP was firing the Bindable event before the other script had time to connect it to a function. A yield was added before the Bindable was fired and it works as expected.
Thank you so much!
Really like your games too, especially the New York game!
Thank you
Script 1 is running before Script 2. Yielding is bad practice and you should rarely be using it. For something like this you should use some kind of module structure so your load order is deterministic because both scripts are run in separate threads and their load order can change at any time.
Example:
-- Still using event
require(script2) -- Event is connected
require(script1) -- Event is fired
-- Not using an event (callback in module body)
require(script1) -- Stuff is done
require(script2) -- After when event would fire and stuff is done