I want to build a zone so that exploiters cant just fly outside of the map to avoid the bomb in a bomb pass game I am making.
So my idea right now is a zone that checks every few seconds to kill any players outside the zone.
This code goes through “inGameFolder” (just a folder that contains number values which are named after the players in game)
I have heard of the zone module, but I do not know how to incorporate it into my code, and I need to be able to change the zone in the middle of a game (parts of map disappear)
My current code works fine, but it is very laggy and there are definitely ways to exploit it.
All the players have a hitbox part inside them that might make this less laggy.
All my maps have a group called “bounds” that contain many parts to build the safe zone.
function checkSafe()
task.spawn(function()
if zone then
for i, v in pairs(inGameFolder:GetChildren()) do
local char = players:FindFirstChild(v.Name).Character
local hitBox = char:FindFirstChild("Hitbox")
if char and hitBox then
local safe = false
for i, bound in pairs(zone:GetChildren()) do
for i, v in pairs(workspace:GetPartsInPart(bound)) do
if v == hitBox then
safe = true
end
end
end
if safe ~= true then
local human = char:FindFirstChild("Humanoid")
if human then
human:TakeDamage(5000)
if inGameFolder:FindFirstChild(char.Name) then
inGameFolder[char.Name]:Destroy()
end
human.Health = -1
if v then
v:Destroy()
end
else
if v then
v:Destroy()
end
end
end
else
v:Destroy()
end
end
end
end)
end
--example of how it works
zone = map.Bounds
while wait(2) do
checkSafe()
end