✓ Accepted answer
local touched = {};
local Part = workspace.Part;
local Players = game:GetService("Players");
function isInTable(val, tab)
for i,v in pairs(tab) do
if val == v then return true end
end
return false
end
function removeFromTable (val, tab)
local newTab = {};
for i,v in pairs(tab) do
if v ~= val then
table.insert(newTab, val)
end
end
return newTab
end
function getNotTouchedPlayers ()
local notTouched = {};
for num, player in pairs(Players:GetPlayers()) do
local hasTouched = isInTable(player, touched)
if not hasTouched then table.insert(notTouched, touchedPlayer) end
end
return notTouched
end
Part.Touched:Connect(function(hit)
if hit and hit.Parent:FindFirstChildOfClass("Humanoid") then
local Player = Players:GetPlayerFromCharacter(hit.Parent)
if not Player then return end
if isInTable(Player, touched) return end
table.insert(touched, Player)
delay(1, function()
touched = removeFromTable(Player, touched)
end)
end
end)
spawn(function()
while true do
wait(1)
local notTouching = getNotTouchedPlayers()
for i,v in pairs (notTouching) do
v:LoadCharacter()
end
end
end)
2 comments
So you want players who have not touched the part to be the ones getting loaded, but only after one second has passed when being touched? You can insert the players who have touched into a table for this. Then loop through all the ones who haven't and load them.
That's what I understood from your explanation. Let me know if that's not what you meant.