How to see if player joined server at least 5 mins earlier

Hello developers, I was wondering if it is possible to see if a player has joined the server within the past 5 minutes.

If you are wondering what’s this is for, I am making a server locking system, and if the player disconnects, they can rejoin without having to ask for the host to open the server again.

Here is the system that locks/unlocks the server,

local groupid = 14054990
local Host = 200
local staff = 150


game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msgenable)
		if msgenable == "!StaffLockOn" then
			if plr:GetRankInGroup(groupid) >= Host then
				if script.Value.Value == false then
					game.ReplicatedStorage.StaffLock:FireAllClients()
					script.Value.Value = true
					script.Bell:Play()
					print("Message Ran")

				end
			end
		end
	end)
end)

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msgdisable)
		if msgdisable == "!StaffLockOff" then
			if plr:GetRankInGroup(groupid) >= Host then
				if script.Value.Value == true then

					script.Value.Value = false
					script.Bell:Play()

				end
			end
		end
	end)
end)


game.Players.PlayerAdded:Connect(function(plr)
	if script.Value.Value == true then
		if plr:GetRankInGroup(groupid) >= staff then
				plr:Kick("                         AirMayora System |                                                    Unfortunatly, we have Staff Locked the server, please join when asked in order to not be late. If you believe this is incorrect, please contact a member of staff.")

		end
	end
end)

Here’s what you can do.

  • add a value with the player’s join time in EPOC time

  • save this data when player leaves, with the server’s job ID

  • when the player joins server, check if the player has this data and check if the server’s Job ID matches with the job ID in the server + if the current EPOC time - Data EPOC time is under or is equal to 300.

If you have any questions feel free to ask :upside_down_face:

local players = game:GetService("Players")

local playerTimes = {}

players.PlayerAdded:Connect(function(player)
	if playerTimes[player.UserId] then
		if (tick() - playerTimes[player.UserId]) <= 300 then
			print("Player rejoined within 5 minutes!")
		end 
	end
end)

players.PlayerRemoving:Connect(function(player)
	playerTimes[player.UserId] = tick()
end)

I used the player’s UserId property as the player instance itself would be different between sessions.

Heyo, I appologise for taking ages to reply, :c school. But how would I put this script into the script i’ve already got?