Is there a way to make the script keep running while executing a function()

So, i have a script for buying items in my game, and i made a notification for it that says You Bought: {Item}, but the problem is that it only buys the item after all the notification script ends

And this is a problem because the notification uses 2 tweens and lots of task.wait() so it takes quite a while

Can anyone help me if theres a way to make the script run at the same time as the function?

And no i cant put the notification after or at the time the player buys cuz of the anti cheat system, so it would take about 3 seconds of wait for the notification to appear

check out coroutines :slight_smile:, I dont believe they utilize true multithreading but they should work completely fine for what your attempting to achieve.

1 Like

Thanks for the help :slight_smile: i will mark @Fifth_5 answer as solution due to it being easier for me

2 Likes

This post has good simple examples of how to use task.spawn and task.delay either of which would work well for what you are trying to do.

1 Like
task.spawn(function()
	task.wait(10)
	print("10 seconds have passed!") --This prints after 10 seconds.
end)

print("Hello world!") --This prints first.

task.spawn() will likely be the simplest for you to use.