Hello! I am currently using DataStore2 to make the player gain time when stepped out of SafeZone and pause time when stepped into SafeZone. The problem I am currently having is I don’t see a way to stop the Increment() function for DataStore2, gaining time is no issue but when I go into SafeZone I can’t figure how to pause the time and it keeps on counting. I tried looking through the DataStore2 API but couldn’t find much on it If anyone could help me out I’d really appreciate it. Thank you!
Code I am using
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local DataStore2 = require(ServerScriptService.DataStore2)
local Zone = require(game:GetService("ReplicatedStorage").Modules.Zone)
local Container = game.Workspace:WaitForChild("SafeZone")
local zone = Zone.new(Container)
Players.PlayerAdded:Connect(function(player)
local Folder = Instance.new("Folder")
Folder.Name = "SafeCheck"
Folder.Parent = player
local BoolValue = Instance.new("BoolValue")
BoolValue.Name = "IsTime"
BoolValue.Parent = Folder
zone.playerEntered:Connect(function()
BoolValue.Value = true
if BoolValue.Value == true then
local pointStore = DataStore2("points", player)
pointStore:Increment(0)
end
end)
zone.playerExited:Connect(function()
BoolValue.Value = false
if BoolValue.Value == false then
while true do
task.wait(1)
local pointStore = DataStore2("points", player)
pointStore:Increment(1)
end
end
end)
end)
Problem I am having
https://gyazo.com/8e0d60b5421ec5cabbc4a4726c2f7a5f