Wait() or task.wait() cancels thread execution

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)

3 Likes

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

2 Likes

Nope, didn’t do it
character limit

2 Likes

probably engine bug, no idea what’s wrong
maybe try outside studio? I actually have no clue

2 Likes

Maybe there is something wrong with the Gui variable?

*edit my bad forgot that it cancels at task.wait

2 Likes

I’m pretty sure that’s not the issue, because the first tween works as usual

3 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.”

2 Likes

I tried this as a standalone function inside a regular script, gave the same results.

2 Likes

Probably an engine bug, try restarting studio.

Works for me:

I’m pretty sure that won’t do anything because I’ve restarted studio many times since this issue came up.

2 Likes

Did it work before, like did it stop working suddenly?

1 Like
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

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)

I’ve stated this before.
char limit

local tween = ..:Play()

tween.Completed:Once(function()
-- other tween
)

How about this

I can try that, however the goal is to wait 3 seconds before the gui disapears.

game.Debris:AddItem(Gui,3) should work then

What if you try spawning the function from the requiring script instead of in the module?

task.spawn(require(Module))

Thanks everyone for the help, but I decided to use an open source notification system instead.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.