hello.
I am trying to create a list of users who can enter only for a certain period of time when they pass through the door.
Therefore, I entered a code to delete the user’s data when the expiration date has passed, but it is not actually deleted, so I ask for advice.
I’d appreciate it if you could help me.
※ We are using Google Translate, so please understand that the translation is not smooth.
※ I did a prior search, but couldn’t find it, so I’m posting it.
[ This is a server script. ]
local part = script.Parent
local Table = {}
local Count = 0
local chack = true
local currenTime = 0
local LimetTime = 10
local function Tou( hut )
local Humanoid = hut.Parent:WaitForChild("Humanoid")
if chack then
chack = false
local Player = game:GetService("Players"):GetPlayerFromCharacter( hut.Parent )
local Time = os.time()
if Humanoid then
print("===== ↓↓↓ Insert new table value ↓↓↓ =====")
local No = #Table + 1
Table[ No ] = { ["Name"] = Player.Name , ["Time"] = Time }
print("======= ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ========")
print("=======================================================")
print("===== ↓↓↓ For checking intermediate table values ↓↓↓ =====")
for _ , v in ipairs( Table ) do
print( _ , v.Name , v.Time )
end
print("======= ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ========")
print("=======================================================")
print("===== ↓↓↓ Display tables out of date ↓↓↓ =====")
for _ , v in ipairs( Table ) do
if v ~= nil then
local RealTime = Time - v.Time
print( "v ~= nil" , RealTime )
if ( RealTime) > LimetTime then
v = nil
print( "v = nil" , RealTime , _ , v )
end
else
print( "v == nil" )
end
end
print("======= ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ========")
print("=======================================================")
print("===== ↓↓↓ Deleting an expired table ↓↓↓ =====")
local currenTable = {}
for _ , v in ipairs( Table ) do
if v ~= nil then
print(_ ,"v:", v )
currenTable[ #currenTable +1 ] = v
-- print( "currenCount :" , #currenTable )
else
print( "v == nil" )
end
end
Table = currenTable
print( "Total currenCount :" ,#currenTable , #Table )
print("======= ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ========")
print("=======================================================")
print("======= For checking intermediate table values =========")
for _ , v in ipairs( Table ) do
print( _ , v.Name , v.Time )
end
print("======= ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ========")
print("=======================================================")
wait( 3 )
chack = true
end
end
end
part.Touched:Connect( Tou )
[ The image is the resulting value. ]