so i have this script for a client timer, so when the player leaves the game, timer datastore and then when he rejoin again the timer continues as of the last time he was online,
but i have it all on the server because i cant put it in the client because it is crutial to my game and i cant make exploiters change the values of the time,
but anyways my concern is that the way my system works is with while wait(1) do loop, for each player, so wont that lag the server considering my max player count in a server is 10, also it has calculations so it checks if a week has passed or a month, or half a month, or a day
so heres the script
local DayLength = 15 -- in minutes
local HourLength = 1 -- in minutes
local SecondsInDay = DayLength * 60
local SecondsInHour = HourLength * 60
function CheckIfWeek(number)
if number % 7 == 0 then
return true
else
return false
end
end
function CheckIfHalfMonth(number)
if number % 14 == 0 then
return true
else
return false
end
end
function CheckIfMonth(number)
if number % 28 == 0 then
return true
else
return false
end
end
game.Players.PlayerAdded:Connect(function(plr)
repeat wait() until plr:FindFirstChild("PlayerTimer")
wait()
while wait(1) do
plr.PlayerTimer.DayTimer.Value += 1
plr.PlayerTimer.HourTimer.Value += 1
if plr.PlayerTimer.HourTimer.Value >= SecondsInHour then
plr.PlayerTimer.HourTimer.Value = 1
game.ReplicatedStorage.TimerFolder.FireClientWhenHourPassed:FireClient(plr)
game.ReplicatedStorage.TimerFolder.FireServerWhenHourPassed:Fire(plr)
end
if plr.PlayerTimer.DayTimer.Value >= SecondsInDay then
plr.PlayerTimer.DaysPlayed.Value += 1
plr.PlayerTimer.DayTimer.Value = 1
game.ReplicatedStorage.TimerFolder.FireClientWhenDayPassed:FireClient(plr)
game.ReplicatedStorage.TimerFolder.FireServerWhenDayPassed:Fire(plr)
if CheckIfWeek(plr.PlayerTimer.DaysPlayed.Value) then
game.ReplicatedStorage.TimerFolder.FireClientWhenWeekPaseed:FireClient(plr)
game.ReplicatedStorage.TimerFolder.FireServerWhenWeekPaseed:Fire(plr)
end
if CheckIfMonth(plr.PlayerTimer.DaysPlayed.Value) then
game.ReplicatedStorage.TimerFolder.FireClientWhenMonthPaseed:FireClient(plr)
game.ReplicatedStorage.TimerFolder.FireServerWhenMonthPaseed:Fire(plr)
elseif CheckIfHalfMonth(plr.PlayerTimer.DaysPlayed.Value) then
game.ReplicatedStorage.TimerFolder.FireClientWhenHalfMonthPaseed:FireClient(plr)
game.ReplicatedStorage.TimerFolder.FireServerWhenHalfMonthPaseed:Fire(plr)
end
end
end
end)
so if you see there are these functions that will fire every second to check the time value, but im worried that with 10 people in the server (and possibly more) it would lag because every second the server will do a calculations for every single player to check if their client time’s timer has passed a day, week, half month, or a month
if it does indeed cause lag in the server then how can improve it? and if it dosent then kindly let me know
any help will be appreciated,