How To Stop Everything (Pause The Game)

In my game i want to be able to pause the game for a time. It is a survival game, where enemies are running towards player, and player is shooting automatically at them. I want them to stop and player to stop shooting when player levels up, and then after some time resume everything.

No need to provide full scripts, i am very good at scripting, just give me an idea.

3 Likes

You can disable and enable scripts

2 Likes

can you can add a boolvalue to the workspace which all your scripts and listen to prevent further execution’s, or just disable script.

1 Like

Like a while true function.
while true do
wait()
If game.Workspace.BoolValue.Value == true then
for i, v in pairs(game.Workspace:GetDescendants()) do
if v:IsA(„LocalScript“) or v:IsA(„Script“) then
v.Disabled = true

For the v in pairs function you have to locate every script since i dont think all of your script are located in workspace…

1 Like
for i,v in pairs(game:GetDescendants()) do 
     if v:IsA("BasePart") then
          v.Anchored = true
   elseif v:IsA("Script") or v:IsA("LocalScript") then
          v.Disabled = true
     end
end
2 Likes

Disabling a script will terminate execution, not halt it. If you want to truly have a game halt during execution, you need to set up every script to connect to some event and, upon receiving the event, internally pause their execution.

1 Like

@0xzMq , @swatkevin123456789 , @madonchik123 , @itsLevande

My sincere gratitude to you all for trying to help. Unfortunately, none of this is exactly what i want. There’s a thing in Unity C# where you do time.TimeScale = 0, and everything stops, and then you put it back to 1 to resume (you literally stop time). I was looking for something similar to that. The solutions you offered will work, with some issues, but they are hacky workarounds (nothing wrong with that, just not something im currently looking for).

Instead of this i just modified my game design to not need a pause.

There’s none sadly, but there’s one for Particle Emitters, also StreamingEnabled somewhat has a “Pause”, but yea you’re basically gonna have to make your own pause as there’s no TimeScale generally.

https://developer.roblox.com/en-us/api-reference/enum/StreamingPauseMode

1 Like

This one is quite complicated. You have to anchor every BasePart in the workspace and disable all functional stuff include animations, values, scripts, etc that are running or planned to run.

local VelocityDictionary = {}
local function Pause()
	for _, p in pairs(workspace:GetDescendants()) do
		if p:IsA("BasePart") then
			if not p.Anchored then
				VelocityDictionary[p] = {p.Velocity, p.RotVelocity}
				p.Anchored = true
			end
		end
	end
end
local function Play()
	for p, Velocity in pairs(VelocityDictionary) do
		p.Velocity = Velocity[1]
		p.RotVelocity = Velocity[2]
		p.Anchored = false
	end
	VelocityDictionary = {}
end

Pause.rbxl (74.7 KB)

1 Like

You mean like the effect in the roblox game hours? When you fight against bosses, amd you have the green character equipped you can stop time for 5 seconds. Literally EVERYTHING stops, also effects like rain or blasters. Same effect is in the roblox game slap, if you have a specific slap tool equipped you can stop time for a bit.