I’ve made this system that detects if a player is inside of a part, and if they are then kick them, but it’s a bit laggy. How can i improve it and keep it short??
function module.activateBarriers()
local map = game.Workspace.Assets:FindFirstChild("Map")
if not map then
return
end
local barriers = map:FindFirstChild("Barriers")
if not barriers then
return
end
task.spawn(function()
while wait() do
if #barriers:GetChildren() < 1 then
return
end
for i, barrier in pairs(barriers:GetChildren()) do
if barrier.Name ~= "Barrier" and not game.Workspace.Assets.Doors.Locked:FindFirstChild(barrier.Name) then
barrier:Destroy()
else
local results = workspace:GetPartsInPart(barrier)
if results then
for i, part in pairs(results) do
if part.Name == "HumanoidRootPart" then
local character = part.Parent
local player = players:GetPlayerFromCharacter(character)
if character and player then
if roundInfo.Players:FindFirstChild(player.Name) then
player:Kick("Out of bounds")
end
end
end
end
end
end
task.wait(.05)
end
end
end)
end