Pretty explanatory by the title itself, i tried putting task.wait(2) and it worked perfectly fine but i want to be sure that every script is “Ready” before the main script fires the event otherwise some scripts may miss the event being fired
maybe using waitforchild?
local Event = game.ReplicatedStorage:WaitforChild("RemoteEvent")
if Event then
print("Event ready to be fired.")
end
Wait what is the difference between :Fire() and :FireAll() ?
oh nvm i can’t use :FireAll() inside a bindable event
Mostly the situation is that the “MainScript” fires the even too fast, it has to wait for atleast the scripts to have done, the listener ones, They all are childrens so maybe something about WaitForChild?
last time i tried waiting for remote events my code would yield infinitely 100% of the time
Maybe if you check if the scripts are loaded, and if they are, fire the event?
Basically i have this script
UpdateInventoryEvent.OnClientEvent:Connect(function(updatedInventory)
currentPlayerInventory = updatedInventory
bindable:Fire(currentPlayerInventory)
print("Fired")
end)
bindable is the bindable event, since it gets the “OnClientEvent” too fast, it sends the script as soon as the player joins, i want to make sure that this script “Fires” the currentPlayerInventory AFTER all the scripts have initialized, or atleast are ready to get the event
yeah but bindable event doesn’t have :FireAll()
I feel like this is more of a logic issue and not a coding issue.
The problem here is that the event gets fired too fast so you need to implement something that waits for the other scripts to be loaded to fire the event.
For this you can use something like an Attribute and once the player is fully loaded you switch the value of said Attribute to true. Now, before the bindable event is fired it should wait for the player loaded attribute to be true. Example:
UpdateInventoryEvent.OnClientEvent:Connect(function(updatedInventory)
currentPlayerInventory = updatedInventory
repeat wait(.5) until player:GetAttribute("PlayerLoaded")
bindable:Fire(currentPlayerInventory)
print("Fired")
end)
I don’t know if my explanation was clear or if this was what you were looking for as a solution. Hope this helped!
so you are saying something like the characterload method?
yeah doing CharacterAppearanceLoaded worked
Code:
UpdateInventoryEvent.OnClientEvent:Connect(function(updatedInventory)
plr.CharacterAppearanceLoaded:Connect(function()
currentPlayerInventory = updatedInventory
bindable:Fire(currentPlayerInventory)
print("Fired")
end)
end)
for anyone trying this solution: It plays only if the character is fully loaded, in my situation it is perfect
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.