xnlogical
(xnlogical)
January 31, 2024, 11:13am
1
Hello developers, I’m having an issue with threads where wait() and task.wait() both cancels thread execution. I’ve never seen this issue nor experienced it myself, so thank you in post.
Code:
return function(Player: Player, Message: string)
local t = coroutine.create(function()
local Gui = Player.PlayerGui.WarnGui.Warning:Clone()
Gui.Parent = Player.PlayerGui.WarnGui
Gui.Text = ("Notification: %s"):format(Message)
Gui.Name = Message
local Sfx = Sounds.PaperWrite2:Clone()
Sfx.Parent = Gui
Sfx:Play()
warn("fading in")
TweenService:Create(Gui, TweenInfo.new(0.25), { TextTransparency = 0 }):Play()
task.wait(3) -- Cancels thread execution
warn("fading out")
TweenService:Create(Gui, TweenInfo.new(0.25), { TextTransparency = 1 }):Play()
task.wait(0.5)
warn("destroying")
Sfx:Destroy()
Gui:Destroy()
end)
coroutine.resume(t)
end
Notes:
“fading in” prints out, after that nothing gets executed
I’ve tried task.spawn() and spawn()
1 Like
KralEge
(KralEge)
January 31, 2024, 11:17am
2
I dont see anything weird, may you show where the function gets fired overall? maybe it could be related to there
1 Like
xnlogical
(xnlogical)
January 31, 2024, 11:19am
3
It’s a module script called from the server as you can see, it worked before and now it doesn’t. I’m starting to believe that this is an engine bug.
1 Like
KralEge
(KralEge)
January 31, 2024, 11:20am
4
I recommend trying it outside of module script to see what happens and see if it works or not, just in case
1 Like
Could be an engine bug, I tried to reproduce the issue but it works fine for me.
1 Like
xnlogical
(xnlogical)
January 31, 2024, 11:23am
6
I tried executing the thread outside the module script, still doesn’t work.
1 Like
KralEge
(KralEge)
January 31, 2024, 11:23am
7
I think there’s something wrong related to module script as in engine bug, could be me though because it should work.
I think the engine bug is related to module scripts in short
(nevemind)
2 Likes
KralEge
(KralEge)
January 31, 2024, 11:26am
8
wait wait wait
can you define tweenservice INSIDE the function? it might work maybe because we dont see tweenservice getting defined there (I have reasons for you to define it inside the function btw just do it!!)
even if it’s defined outside of function it might work why? I have no idea just got a feeling
1 Like
xnlogical
(xnlogical)
January 31, 2024, 11:28am
9
Nope, didn’t do it
character limit
1 Like
KralEge
(KralEge)
January 31, 2024, 11:31am
10
probably engine bug, no idea what’s wrong
maybe try outside studio? I actually have no clue
1 Like
Maybe there is something wrong with the Gui variable?
*edit my bad forgot that it cancels at task.wait
1 Like
xnlogical
(xnlogical)
January 31, 2024, 11:33am
12
I’m pretty sure that’s not the issue, because the first tween works as usual
2 Likes
It may have to do with the fact that a modulescript only runs once, so there’s conflicting code.
“ModuleScripts run once and only once per Lua environment and return the exact same value for subsequent calls to require.”
“Note that the first call to require on a ModuleScript will not yield (halt) unless the ModuleScript yields (e.g. calls task.wait() ). The current thread that called require will yield until a ModuleScript returns a value.”
1 Like
xnlogical
(xnlogical)
January 31, 2024, 11:44am
14
I tried this as a standalone function inside a regular script, gave the same results.
1 Like
Probably an engine bug, try restarting studio.
Works for me:
xnlogical
(xnlogical)
January 31, 2024, 11:45am
16
I’m pretty sure that won’t do anything because I’ve restarted studio many times since this issue came up.
1 Like
Did it work before, like did it stop working suddenly?
return function(Player: Player, Message: string)
task.spawn(function()
local Gui = Player.PlayerGui.WarnGui.Warning:Clone()
Gui.Parent = Player.PlayerGui.WarnGui
Gui.Text = ("Notification: %s"):format(Message)
Gui.Name = Message
local Sfx = Sounds.PaperWrite2:Clone()
Sfx.Parent = Gui
Sfx:Play()
warn("fading in")
TweenService:Create(Gui, TweenInfo.new(0.25), { TextTransparency = 0 }):Play()
task.wait(3) -- Cancels thread execution
warn("fading out")
TweenService:Create(Gui, TweenInfo.new(0.25), { TextTransparency = 1 }):Play()
task.wait(0.5)
warn("destroying")
Sfx:Destroy()
Gui:Destroy()
end)
end
xnlogical
(xnlogical)
January 31, 2024, 11:48am
19
It was slightly different before, like the GUI wasn’t cloned, etc. but nothing that would effect the thread. (Basically the same in terms of strcutre)
xnlogical
(xnlogical)
January 31, 2024, 11:52am
20
xnlogical:
Notes:
“fading in” prints out, after that nothing gets executed
I’ve tried task.spawn() and spawn()
I’ve stated this before.
char limit