How to make only 5 Players Allowed in a Certain Area

can you show me the new script I mean

Oh okay hold up let me copy it

That is the script I used and I followed your instructions to add the position of where my spawn is.

local ZonePlus = require(4664437268)
local ZoneService = require(ZonePlus.ZoneService)


-- Setup zone
local group = workspace.SafeZone2
local zone = ZoneService:createZone("SafeZone2", group, 0)
local safecheck = false
local playercount = 0
local player = game.Players.LocalPlayer
local table = {}

   
   


-- Create a safe zone by listening for players entering and leaving the zone
local safeZoneCheckInterval = 0.2
local forceFieldName = "PineapplesForLife"
local forceFieldTemplate = Instance.new("ForceField")
forceFieldTemplate.Name = forceFieldName

local connectionAdded = zone.playerAdded:Connect(function(player)
   
   safecheck = true
   if safecheck == true then
      -- checks if there's less than 5 players in the zone
      if playercount < 5 then
         playercount = playercount + 1
         print(playercount)
         print(player.Name)
      else
      -- teleports the player and returns the function if playercount => 5
         local char = player.Character
         if char and char:FindFirstChild("HumanoidRootPart") then
            char.HumanoidRootPart.CFrame = CFrame.new(TeleportPart.Position, char.HumanoidRootPart.Position)  
         end
         return
      end
   end
   
   local char = player.Character
   local forceField = char and char:FindFirstChild(forceFieldName)
   if not forceField then
      forceField = forceFieldTemplate:Clone()
      forceField.Parent = char
   end
end)

local connectionRemoving = zone.playerRemoving:Connect(function(player)
   safecheck = false
   if safecheck == false then
   	playercount = playercount - 1
   	print(playercount)
   	print(player.Name)
   end
   
   local char = player.Character
   local forceField = char and char:FindFirstChild(forceFieldName)
   if forceField then
   	forceField:Destroy()
   
   	end
   
end)

zone:initLoop(safeZoneCheckInterval)
1 Like

Okay let me try that one now Thanks!

So this time where would I replace my position?

char.HumanoidRootPart.CFrame = CFrame.new(TeleportPart.Position, char.HumanoidRootPart.Position) 

like for that part how would I be able to put (20,20,20) there?

Working! Thanks So Much! I have multiple maps so would this work for multiple zones?

Thanks!

You’re probably going to have to make another script and safezone

local group = workspace.SafeZone2 -- Safezone3, 4, 5 etc.
local zone = ZoneService:createZone("SafeZone2", group, 0) -- Safezone3,  4, 5 etc.

Okay Thanks would you like to check out my game?