Im thinking about making a [blank] type of game and I want to know if its possible to make a pause system. An example would be I press “p” and everything and everyone, all the guis, EVERYTHING freezes and the game just stops playing, but then I unpause and the game starts working again. Is it possible to do that? If so I’d like know how to do it please. I have no clue how I would begin scripting it. Would there be like an api or something for it?
Thanks
The only way you would be able to do it is make code everything yourself to act a certain way while the game is “Paused” which would give it the effect of being paused.
This “pause” system would only have to be done locally as it would otherwise freeze everyone else in the server in time, and I don’t think players would want that .
You could use some sort of function that just sets all moving part’s base velocity to 0 or another idea would be to clone every thing visible by the player, i.e the Workspace’s descendants to somewhere else and change the player’s camera locally, to face that area upon a certain key being clicked, using UserInputService binding a key with the function.
You could make a function that will pause any action of the actual game, but you would need to make how the pause function will act and what will it do, here is a not tested code that might help you:
function Pause()
--[[ Lighting Behaviour ]]--
game.Lighting.Ambient.Color = -- whatever ambient
--[[ Humanoid Behaviour ]]--
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local char = Player.Character
local Humanoid = char:WaitForChild("Humanoid")
Humanoid.WalkSpeed = 0
--[[ UI Behaviour ]]--
local PlayerGui = Player:FindFirstChild("PlayerGui")
local PauseGui = PlayerGui:FindFirstChild("Pause")
PauseGui.Enabled = true
end
You might want to use some form of module scripts / _G variables when you do this, Because:
For example, if you’re running a loop you can do this:
while wait() do
if _G.Paused == false then
--execute code here if game is NOT paused, else if it is, it won't do anything
end
end
This will also apply to OnClientEvent functions so that the player doesnt receive updates from the server either.
You may want to log the player’s velocity also before you “pause” the game so that when you unpause, you set the player’s velocity back to the logged velocity making the player move again.
Theat’s just a few more things to consider when “pausing” a game
Why is Roblox not pausable? Maybe because other clients are moving even when you press escape? Maybe because someone can hurt you while you ‘pause’ the game?
Hence, do this from the client then. Make the player invincible (might be abusable tho’), (if you want, freeze other players, or everything, in the client, since it will appear as other players aren’t moving then)
My opinion tho, would be to use a Menu that covers the whole screen, or a menu that changes the camera subject to something else that also shows a Menu.