I’m trying to make branching dialogue with choices, and there’s one BindableEvent that handles giving new choices and dialogue to the GUI, and one BindableEvent that handles deleting the old, previous choices.
The problem is that when you choose an choice in the dialogue, it adds the new dialogue choices and deletes them at the same time, along with the previous options.
button.MouseButton1Click:Connect(function()
clearEvent:Fire() --Deletes all choice buttons in GUI
populateEvent:Fire(button.Dialogue) --Adds new choices
end)
local rep = game:GetService("ReplicatedStorage")
local parent = script.Parent
rep.Chat.ClearOptionsClient.Event:Connect(function()
local optionChildren = parent.OptionFrame:GetChildren()
for _, child in ipairs(optionChildren) do
if child:IsA("ImageButton") then
child:Destroy()
end
end
end)
--The clear event
I’ve tried placing a task.wait(0.1) after the clearEvent, but that doesn’t work either. I also tried combining these two events into one and just making the option clearing happen before the new options are added, but that still didn’t work. I just need some method to clear the options and only add the new options once the old ones are cleared. Any help is appreciated.
when you click the button, both events run at once, they are asynchronous, all you have to do is to delay the fire for populateEvent or make clearEvent yield.
However, you are overusing signals, you should make the clear choices a function.
On this image, once a choice is selected, I immediately clear all the active choices and then start the next speech.
The reason why the latter work is because they are not asynchronous calls, they’re simply functions with loops that will yield the thread, and as the title says, they fire in order and don’t conflict each other.
I wanted to use an event because I was figuring it would be easier since I wouldn’t need the copy and paste the function into every dialogue script, I could just reference the event and there’d only be 1 script that fires the event in the GUI.