The problem I face is whenever I call the below function, a previous call of it is still running in the background because of my repeat loops.
So when I call it a first time, it’s fine works perfectly. But the second time I call it, the first call is still running the background, and thus I get 2x the amount of Notifications because it’s still running from my old job. I need it to basically only run once at anytime
So whenever a player changes their job, I fire this function which basically deals with their jobs time and tells them when to go to work etc.
function JobService:Control(player)
local User = PlayerData[player.UserId]
if not User then return end
local JobInfo = JobData[User.Job]
if not JobInfo then return end
for _, v in pairs(JobInfo.Days) do
if v == Day.Value then
repeat wait() until Lighting:GetMinutesAfterMidnight() == JobInfo.StartTime * 60
Notification:FireClient(player, 'Job', User.Job, 'Start')
repeat wait() until Lighting:GetMinutesAfterMidnight() == JobInfo.EndTime * 60
Notification:FireClient(player, 'Job', User.Job, 'End')
if JobInfo.Pay then
UpdateCash(player, JobInfo.Pay * (JobInfo.EndTime - JobInfo.StartTime))
end
UpdateExp(player, JobInfo.Exp)
end
end
end
Problem is if I change jobs, this function gets fired again, but! the previous function is still running and so in the previous function, the 2 repeat lines are still going, and so I’ll get a notification for my previous job
repeat wait() until Lighting:GetMinutesAfterMidnight() == JobInfo.StartTime * 60
-- and....
repeat wait() until Lighting:GetMinutesAfterMidnight() == JobInfo.EndTime * 60
So how can I disconnect this function everytime it’s called? Cause if I call this function several times, it’ll be running 7 times over.