local debounce = false local function Touched (hit) if debounce == false then debounce = true local player = game.Players:GetPlayerFromCharacter(hit.Parent) player:LoadCharacter() wait(1) debounce = false end script.Parent.Touched:Connect(Touched)
Does someone know how i could make this script so that only players who haven't touched the part for at least a second could load his/her character and those who have touched it before the one second timeout have to wait?
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)