How do I make a safe zone but pauses time?

Hi I want to make a safe zone that pauses players time when they get in and when they get out there time goes again

local TimeAlive = 0
local Shards = 0
local Exp = 0
local Levels = 0
local GUIClient = false
local Humanoid;


game:GetService("Players").PlayerAdded:Connect(function(P)
	local Stats = Instance.new("Folder", P)
	Stats.Name = "leaderstats"
	local ClientTester = Instance.new("Folder", P)
	ClientTester.Name = "ClientTester"


	local BT = Instance.new("IntValue", Stats)
	local TA = Instance.new("IntValue", Stats)
	local SHARDS = Instance.new("IntValue", Stats)
	local EXP = Instance.new("IntValue", Stats)
	local LEVELS = Instance.new("IntValue", Stats)
	local GUICLIENT = Instance.new("BoolValue", ClientTester)
	TA.Name = "TimeAlive"    
	BT.Name = "BestTime"
	SHARDS.Name = "Shards"
	EXP.Name = "Exp"
	LEVELS.Name = "Levels"
	GUICLIENT.Name = "GUICLIENT"
	
	
	GUIClient = GUICLIENT
	TimeAlive = TA
	BestTime = BT
	Shards = SHARDS
	Exp = EXP
	Levels = LEVELS

	P.CharacterAdded:Connect(function(C)        
		Humanoid = C:WaitForChild("Humanoid")
	end)
end)


while true do
	wait()
	if Humanoid then
		if Humanoid.Health > 0 then
			TimeAlive.Value += 1
			print(TimeAlive.Value)
			wait(1)
		else
			if BestTime.Value > 0 then
				if TimeAlive.Value > BestTime.Value then
					BestTime.Value = TimeAlive.Value
					print("Giving A New Best Time!")
				end
			else
				BestTime.Value = TimeAlive.Value

			end

			print("Time Alive ", TimeAlive.Value, " Best Time ", BestTime.Value)

			TimeAlive.Value = 0
			wait(.1)
		end
	end
end
2 Likes

You should check out Zone+. ZonePlus v3.2.0 | Construct dynamic zones and effectively determine players and parts within their boundaries - #71 by ForeverHD

1 Like

How would I pause there time though?

1 Like

You could create a Bool Value in the Player that gets changed when the player is in the safezone, then add a check if the value is true.

1 Like