-
What do you want to achieve? Keep it simple and clear!
Trying to create a region, upon entering which a player is added to the table, (and later teleports to another place.) -
What is the issue? Include screenshots / videos if possible!
The problem is i don’t know how to remove a player from the table when he leaves the region.
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Made a check for the presence of a player in the table, and the limit of players. But, i don’t know what to do next.
local regionPart = script.Parent
local playersInRegion = {}
local limit = 10
coroutine.resume(coroutine.create(function()
while wait(1) do
print("Total Players: "..#playersInRegion)
end
end))
while wait(1) do
local region = Region3.new(regionPart.Position - (regionPart.Size/2), regionPart.Position + (regionPart.Size/2))
local partsInRegion = game.Workspace:FindPartsInRegion3(region, regionPart, 200)
for i, part in pairs(partsInRegion) do
if part.Parent:FindFirstChild("Humanoid") ~= nil then
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if #playersInRegion < limit then
if table.find(playersInRegion, player) then
warn(tostring(player).." is is already in table!")
else
table.insert(playersInRegion, player)
print(tostring(player).." found in region, Added to table.")
end
else
print("Max Players!")
end
end
end
end