So I have this snippet of code that comes after a :Wait() statement, but after the wait is passed, it fires twice.
if i == 1 then
opMenu.Option1.Text = charTexts[next][op].Message
opMenu.Option1.Visible = true
opMenu.Visible = true
task.spawn(function()
warn("Waiting...")
opMenu.Option1.Activated:Wait()
warn("Unwaiting!")
if changed == true then return end
changed = false
chosen = op
pressed = true
warn("They chose "..op)
warn(" ")
end)
else
(Simple Terms: The message “Unwaiting” will be warned twice once the activated statement has been, well, activated)
Information: This is inside of an ipairs loop which is inside of an if statement. This statement is located within a while loop inside a function.
I’ve been trying to figure out why this happens, previously the :Wait() stopped the double printing but now it’s happening again.
For more information, I have a module full of messages and outcomes that the player can choose, such as when the thing says “Hey there!” the player can choose between “Yo” and “Bye”. This code is for displaying the player’s options and detecting when they are clicked.
If you need more details, please inform me. Thanks, @Pish85 signing out.
Strangely, no, only that is double printing. I put prints at the start of function, start of loop, start of if statement, literally everywhere that indented
if none of the other prints/warns go twice, there’s no reason it would happen, as code runs linearly, and if "Unwaiting!" prints twice, at the very least "Waiting..." would fire
It’s designed so that the code fires after the button is pressed. If you didn’t read the whole post, the code says OpMenu.Option1.Activated:Wait(), showing that I want to fire the code after the button is pressed, not a set time.
If that’s not what you meant, I always use task.wait. I just said wait cuz it’s shorter.
The problem is, “Waiting” prints once, but “Unwaiting” prints twice. I’m assuming that it’s because of events inside events or so, but that was previously fixed by replacing :Connect with :Wait
For the first part, what I’m saying is I previously had this same issue, so I replaced my Connect statement with a Wait. However, now that the issue is back, I’m worried I did something wrong regarding that chance.
For the second part, I’ll try using Once and report back.
The issue is likely that Activated:Wait() is being triggered twice—check if the button is being clicked multiple times or if the function is being spawned more than once.
I think you should use opMenu.Option1.Activated:Connect() instead of Wait(), and disconnect the connection after the first activation to prevent multiple triggers.