I'm making a stage-based game like left for dead. I'm making a safe room where all players must be to move on to the next stage of the level, so I want to find all the players on the pad then see if that's all the players on the server. If so, open the door. This is what I have so far.
local door = script.Parent.SaferoomDoor
door.Transparency = 0
door.CanCollide = true
local contine = true
local function getplayersinbox(part) -- find players on pad
local Players = game.Players:GetPlayers()
local players = {}
local touching = part:GetTouchingParts()
print(#touching)
for i=1,#touching do
local player = Players:GetPlayerFromCharacter(touching[i].Parent)
if player then
local found = false
for k=1,#players do
if players[k] == player then
found = true
break
end
end
if not found then
table.insert(players,player)
end
end
end
return players
end
while wait() and contine == true do
local players = game.Players:GetPlayers()
local colliding = getplayersinbox(script.Parent.TouchPlate)
-- print(#players.." players")
-- print(#colliding.." tPlayers")
if #players <= #colliding then --if all players in the game are on the pad open the door
door.Transparency = 0.5
door.CanCollide = false
contine = false
print("door open")
end
end
The code seems to work if I make the pad a huge cube and walk into the side of it. I want it to be the floor if possible. I'm pretty new to Roblox development and I didn't write the function to find the players so I may be missing something obvious. I want to use touching a part instead of in an area so it would be easy to reuse, but if there is a way to check in an are that can be moved or resized easily that would be fine.
