What do you want to achieve? Keep it simple and clear!
I have a GUI which is visible only when the server fires a client event and then disappears after a certain number of seconds.
What is the issue? Include screenshots / videos if possible!
If another event is fired while the countdown for the GUI to disappears is still going on, the GUI will only appear briefly before being made invisible again rather than the timer being reset.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Try this (there’s probably a more efficient way but it should get the job done):
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage.Remotes
[...]
local dontClose = false
local ran = false
Remotes.Dialogue.OnClientEvent:Connect(function(Speaker, Speech, DisplayFor)
if ran == true then
dontClose = true
end
ran = true
Dialogue.Visible = true
Dialogue.Speaker.Text = Speaker
Dialogue.Speech.Text = Speech
wait(DisplayFor)
if dontClose == true then
dontClose = false
else
Dialogue.Visible = false
end
ran = false
end)
Depending on how the event is called this could leave the dialogue always visible say if it is called with a 2 second delay and immediately called with a 1 second delay.
make event clones the gui, it better, and use corountines to do many things at the same time, it’s easier that firing remote to one gui, make state or something like that, or maybe cooldovvn