Hello there, I’ve been trying to solve this issue, where people get their time added when they’re out of a safe zone. The issue is that when the player enters into the safe zone again, the time continues and the loop running wont stop. Break doesn’t work either.
What I am trying to achieve is that you actually can stop the time when entering safe zone again.
Server Script:
game.ReplicatedStorage.Remotes.AddTime.OnServerEvent:Connect(function(plr, bool )
local leaderstats = plr:WaitForChild("leaderstats")
local ctime = leaderstats:FindFirstChild("Time")
while wait(1) do
if bool == true then
ctime.Value = ctime.Value + 1
elseif bool == false then
break
end
end
end)
Local Script
safezone.localPlayerEntered:Connect(function()
local inZone = safezone:findLocalPlayer()
if inZone then
game.ReplicatedStorage.Remotes.Safe:FireServer()
game.ReplicatedStorage.Remotes.AddTime:FireServer(false)
print("In Zone")
end
end)
safezone.localPlayerExited:Connect(function()
local inZone = safezone:findLocalPlayer()
if inZone then
else
game.ReplicatedStorage.Remotes.SafeExit:FireServer()
game.ReplicatedStorage.Remotes.AddTime:FireServer(true)
end
end)