So basically, I need a way for a wait trigger in the function not to stop the other code below it.
Example code:
(edit) OOPS I MADE A MISTAKE sorry guys, I said function but I meant a “for” loop. for example:
ExampleRemote.OnServerEvent:Connect(function()
for i, v in pairs(workspace:GetPartsInPart(ExamplePart)) do
print("ExampleText")
wait(1)
print("ExampleText2")
end
--I want this code to run as the loop above is running
print("ExampleText3")
end)
Please help I’ve been trying to fix this for like an hour lol
Haha, I was going to reply with task.delay too, until I realized OP’s code should be doing exactly what they want it too, only if that typo wasn’t there.
First of all, it’s never a good practice to nest functions inside of functions as it creates memory leaks.
But as this is an example, here is a code snippet:
local old_connection = nil
ExampleRemote.OnServerEvent:Connect(function()
if old_connection then
old_connection:Disconnect()
end)
old_connection = ExamplePart.Touched:Connect(function()
print("ExampleText")
task.delay(1,function()
print("ExampleText2")
end)
end)
--I want this code to run as the function above is running
print("ExampleText3")
end)
I know this wont fix the problem entirely, but for my issue it was a touch thing and putting the for i, v loop inside a script in the part worked. I don’t know why i didn’t think of this before lol. Anyway thank you all for the help!