Hello!
I’ve been working on a Safezone module for fun, But im running into some issues.
i’ve tried to add a Table that holds the UserID’s of the players that enter a specified safezone, And it works, it’s just that it inserts multiple instances of the same UserId into the table.
There’s also the issue of this only working for one player.
as soon as a 2nd player enters the Safezone, the already existing player gets their Safezone taken away.
I’ve tried adding another entire table, but that just made the problem worse.
Im Entirely Out of Ideas.
I’ve provided some screenshots and videos of the issue here:
local assets = script.Parent.Assets
local Safezone = {}
Safezone.PlayersInZone = {}
function Safezone.check(self, player)
if player then
if table.find(self.PlayersInZone, player.UserId) then
return true
else
return false
end
end
end
function Safezone.updateSafeZone(self)
local safezoneRegion = Region3.new(workspace.Safezone.Position - workspace.Safezone.Size / 2, workspace.Safezone.Position + workspace.Safezone.Size / 2)
local partsInSafezone = workspace:FindPartsInRegion3(safezoneRegion, nil)
local playersInSafezone = {}
for _, part in ipairs(partsInSafezone) do
local character = part.Parent
if character and character:IsA("Model") then
local player = game:GetService("Players"):GetPlayerFromCharacter(character)
if player and not self:check() then
table.insert(playersInSafezone, player.UserId)
if not character:FindFirstChild("ForceFieldHighlight") then
local ffeffect = assets.ForceFieldHighlight:Clone() ffeffect.Parent = character
end
print(self.PlayersInZone)
end
end
end
for _, userId in ipairs(self.PlayersInZone) do
if not table.find(playersInSafezone, userId) and not self:check() then
local player = game:GetService("Players"):GetPlayerByUserId(userId)
if player and player.Character:FindFirstChild("ForceFieldHighlight") then
player.Character:FindFirstChild("ForceFieldHighlight"):Destroy()
print(player.Name .. " has left the safezone.")
end
end
end
self.PlayersInZone = playersInSafezone
end
return Safezone
and this is how i run it on the server:
runService.Stepped:Connect(function()
safezone:updateSafeZone()
end)
Any help is greatly appreciated! If you need any more information, don’t hesitate to ask!