Hello.
Please watch the video to get a good understanding.
safezone system: you enter, tools get parented somewhere else, you leave, you get tools back
In the first clip the code works fine as the 2nd safezone is excluded, in the 2nd clip the 2nd safezone is included and you can see that it completely breaks.
the code is pretty basic to understand, it’s a region 3 with some checks and when a player is in region3 we parent tools into a secure folder for storage so it’s a safezone, and when they leave they come back. you can see the game literally gets destroyed by using, the same code…
Read the commented code as real code, it’s commented out because when I test it like that, everything works (first clip), but when i unignore it, everything breaks. (second clip)
local region = Region3.new(workspace.Map.Safezones.Safezone1.Position - workspace.Map.Safezones.Safezone1.Size / 2, workspace.Map.Safezones.Safezone1.Position + workspace.Map.Safezones.Safezone1.Size / 2)
--local regionSecondSafezone = Region3.new(workspace.Map.Safezones.Safezone2.Position - workspace.Map.Safezones.Safezone2.Size / 2, workspace.Map.Safezones.Safezone2.Position + workspace.Map.Safezones.Safezone2.Size / 2)
local region2 = Region3.new(workspace.Map.TimeZones.x2.Position - workspace.Map.TimeZones.x2.Size / 2, workspace.Map.TimeZones.x2.Position + workspace.Map.TimeZones.x2.Size / 2)
local region3 = Region3.new(workspace.Map.TimeZones.x4.Position - workspace.Map.TimeZones.x4.Size / 2, workspace.Map.TimeZones.x4.Position + workspace.Map.TimeZones.x4.Size / 2)
local blacklistedNames = {
"FirstPlace";
"SecondPlace";
"ThirdPlace";
}
local regionedPlayers = {}
--local safezone2Players = {}
local x2regionedPlayers = {}
local x4regionedPlayers = {}
coroutine.wrap(function()
task.wait(5)
while true do
local partsInRegion = workspace:FindPartsInRegion3(region, workspace.Map.Safezones.Safezone1, 10000)
--local partsInSecondSafezone = workspace:FindPartsInRegion3(regionSecondSafezone, workspace.Map.Safezones.Safezone2, 10000)
local partsInRegion2 = workspace:FindPartsInRegion3(region2, workspace.Map.TimeZones.x2, 10000)
local partsInRegion3 = workspace:FindPartsInRegion3(region3, workspace.Map.TimeZones.x4, 10000)
for _, v in ipairs(partsInRegion) do
if v.Name == "HumanoidRootPart" then
if v.Parent:FindFirstChild("Humanoid") then
if not table.find(blacklistedNames, v.Parent.Name) then
if v.Parent.HumanoidRootPart then
local charPlayer = v.Parent
local Player = Players:GetPlayerFromCharacter(charPlayer)
if not table.find(regionedPlayers, Player.Name) then
table.insert(regionedPlayers, Player.Name)
end
Player.Values.Safezone.Value = true
require(ServerScriptService.Server.Modules.Main).CombatlogText(Player, "You are inside the safezone! If you leave, you will not lose 15% of your Time.", Color3.fromRGB(0, 255, 0))
if ServerStorage.Storage.UFO.Flying.Value == false then
General:FireClient(Player, "EnableUI")
end
Player.Character.Humanoid:UnequipTools()
for a, b in ipairs(Player.Backpack:GetChildren()) do
if b:IsA("Tool") then
local tempTool = Instance.new("StringValue")
tempTool.Name = "tempTool"
tempTool.Value = b.Name
tempTool.Parent = Player.Values.SafezoneTools
b.Parent = ServerStorage.Storage.Resources.User[Player.Name].TempTools
end
end
for c, d in ipairs(Player.Character:GetChildren()) do
if d:IsA("Tool") then
local tempTool = Instance.new("StringValue")
tempTool.Name = "tempTool"
tempTool.Value = d.Name
tempTool.Parent = Player.Values.SafezoneTools
d.Parent = ServerStorage.Storage.Resources.User[Player.Name].TempTools
end
end
end
end
end
end
end
--[[for _, v in ipairs(partsInSecondSafezone) do
if v.Name == "HumanoidRootPart" then
if v.Parent:FindFirstChild("Humanoid") then
if not table.find(blacklistedNames, v.Parent.Name) then
if v.Parent.HumanoidRootPart then
local charPlayer = v.Parent
local Player = Players:GetPlayerFromCharacter(charPlayer)
if not table.find(regionedPlayers, Player.Name) then
table.insert(regionedPlayers, Player.Name)
end
Player.Values.Safezone.Value = true
require(ServerScriptService.Server.Modules.Main).CombatlogText(Player, "You are inside the safezone! If you leave, you will not lose 15% of your Time.", Color3.fromRGB(0, 255, 0))
if ServerStorage.Storage.UFO.Flying.Value == false then
General:FireClient(Player, "EnableUI")
end
Player.Character.Humanoid:UnequipTools()
for a, b in ipairs(Player.Backpack:GetChildren()) do
if b:IsA("Tool") then
local tempTool = Instance.new("StringValue")
tempTool.Name = "tempTool"
tempTool.Value = b.Name
tempTool.Parent = Player.Values.SafezoneTools
b.Parent = ServerStorage.Storage.Resources.User[Player.Name].TempTools
end
end
for c, d in ipairs(Player.Character:GetChildren()) do
if d:IsA("Tool") then
local tempTool = Instance.new("StringValue")
tempTool.Name = "tempTool"
tempTool.Value = d.Name
tempTool.Parent = Player.Values.SafezoneTools
d.Parent = ServerStorage.Storage.Resources.User[Player.Name].TempTools
end
end
end
end
end
end
end]]
for _, v in ipairs(partsInRegion2) do
if v.Name == "HumanoidRootPart" then
if v.Parent:FindFirstChild("Humanoid") then
if not table.find(blacklistedNames, v.Parent.Name) then
local charPlayer = v.Parent
local Player = Players:GetPlayerFromCharacter(charPlayer)
if not table.find(x2regionedPlayers, Player.Name) then
table.insert(x2regionedPlayers, Player.Name)
end
Player.Values.x2TimeZone.Value = true
end
end
end
end
for _, v in ipairs(partsInRegion3) do
if v.Name == "HumanoidRootPart" then
if v.Parent:FindFirstChild("Humanoid") then
if not table.find(blacklistedNames, v.Parent.Name) then
local charPlayer = v.Parent
local Player = Players:GetPlayerFromCharacter(charPlayer)
if not table.find(x4regionedPlayers, Player.Name) then
table.insert(x4regionedPlayers, Player.Name)
end
Player.Values.x4TimeZone.Value = true
end
end
end
end
for _, v in ipairs(Players:GetPlayers()) do
if not table.find(regionedPlayers, v.Name) then
v.Values.Safezone.Value = false
require(ServerScriptService.Server.Modules.Main).CombatlogText(v, "You are outside of the safezone. If you leave, you will lose 15% of your Time for Combat Logging.", Color3.fromRGB(255, 0, 0))
General:FireClient(v, "DisableUI")
for a, b in ipairs(v.Values.SafezoneTools:GetChildren()) do
if b:IsA("StringValue") then
ServerStorage.Storage.Resources.User[v.Name].TempTools:FindFirstChild(b.Value):Clone().Parent = v.Backpack
b:Destroy()
end
end
for c, d in ipairs(ServerStorage.Storage.Resources.User[v.Name].TempTools:GetChildren()) do
if d:IsA("Tool") then
d:Destroy()
end
end
end
--[[if not table.find(safezone2Players, v.Name) then
v.Values.Safezone.Value = false
print(tostring(v.Name).." | Values = "..tostring(v.Values.Safezone.Value))
require(ServerScriptService.Server.Modules.Main).CombatlogText(v, "You are outside of the safezone. If you leave, you will lose 15% of your Time for Combat Logging.", Color3.fromRGB(255, 0, 0))
General:FireClient(v, "DisableUI")
for a, b in ipairs(v.Values.SafezoneTools:GetChildren()) do
if b:IsA("StringValue") then
ServerStorage.Storage.Resources.User[v.Name].TempTools:FindFirstChild(b.Value):Clone().Parent = v.Backpack
b:Destroy()
end
end
for c, d in ipairs(ServerStorage.Storage.Resources.User[v.Name].TempTools:GetChildren()) do
if d:IsA("Tool") then
d:Destroy()
end
end
end]]
if not table.find(x2regionedPlayers, v.Name) then
v.Values.x2TimeZone.Value = false
end
if not table.find(x4regionedPlayers, v.Name) then
v.Values.x4TimeZone.Value = false
end
end
regionedPlayers = {}
--safezone2Players = {}
x2regionedPlayers = {}
x4regionedPlayers = {}
task.wait(0.01)
end
end)()
Thanks! This has been on my mind for couple of days now, and no succes in any solution.