Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help needed with detecting if there are no players inside a part?

Asked by 5 years ago

This was reposted from the discord server due to not getting an answer. :P I got some help with a function to teleport players into a map if they are touching a part:

local function teleportToGame()
    local partsInRegion = game.Workspace:FindPartsInRegion3(tpRegion, nil, math.huge)
    -- Region, Instance to ignore, maximum part count


    for _, part in ipairs(partsInRegion) do
        -- Iterating through the array returned
        local player = game.Players:GetPlayerFromCharacter(part.Parent)

        if player then -- if player
            player.Character.HumanoidRootPart.CFrame = game.Workspace.gameTeleport.CFrame + Vector3.new(math.random(3,6),math.random(3,6),math.random(3,6))
            workspace.gameGui:Clone().Parent = player:FindFirstChild("PlayerGui")  
        end
    end
end

So I decided to try to reverse engineer the script to make it that if no-one is in the map, the round will end:

local partsInRegion = game.Workspace:FindPartsInRegion3(mapRegion, nil, math.huge)                                                                                                                                                                                                                                                                                                                                                    

    for _, part in ipairs(partsInRegion) do
          local player = game.Players:GetPlayerFromCharacter(part.Parent)
        if player  then
            repeat wait() until player == nil
        end
end

But it just keeps the round going, even if there is no-player inside it. Does anyone know what I might be doing wrong? thanks.

0
why not just keep the current players in a table, seems easier. DinozCreates 1070 — 5y
0
Use the length operator # on the array, and check if < 1 User#24403 69 — 5y
0
^ EpicMetatableMoment 1444 — 5y
0
^ starmaq 1290 — 5y
0
well i tried but it still broke. welp time to go back to the good ol timer system RGamesDev 22 — 5y

Answer this question