Hi, I’m WatchaM3an.
I’m pretty new to the platform. And pretty bored.
I wanna make games, like pretty good games.
and what does every good game have…
you’ve guess it! A pause menu!
I started to search on the devforum and found multiple topics like this one.
But there was one big problem.
Roblox limitations make it difficult to actually pause scripts.
I had two expectations
- Make it universally applicable
meaning it works with threads and task.spawn - Make it actually pause and resume
make it stop on the exact instruction it was about to do
anyway, I started with threads
I made a simple script
local yield = false;
coroutine.wrap(function()
for i = 1, 5 do
if yield then -- if the external thread makes `yield` equal true
coroutine.yield(); -- it yields the thread
end
print(i)
wait(1);
end
end)()
wait(0.9); -- after 1 second (or close to one second),
yield = true; -- it yields the cororutine on line. 6
there was 1 problem with this, it wasn’t really easy to apply.
this became a nightmare.
my second solution was signals
local yield = Instance.new('BindableEvent');
coroutine.wrap(function()
yield.Event:Connect(coroutine.yield);
for i = 1, 5 do
print(i)
wait(1);
end
end)()
wait(0.9) -- yields it after one second
yield:Fire();
This provided an easy way to apply this into real games, if it worked.
There were now one more problem with this
When you fires the event, it DOES yield the thread, but not the right one.
It yields the external thread, but not the actual thread we want.
basically : coroutine.yield() == yield:Fire()
my third solution
a damn virtual machine
I used a interpreter that could interpret luau, which was important because roblox uses luau, not lua.
And I modifed it to actually pause and resume on each instruction. This works without interrupting the external thread, but can also be universally applied to other threads inside the actual thread.
It can literally pause and resume code.
All I need to do is pause tweens, animations…
i’m going to sleep