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

How do i remove a player from a table when he leaves region3?

Asked by 3 years ago

I have tried this

spawn(function()
    while wait() do
        local r3 = Region3.new(car.Platform.Position-Vector3.new(7,0,7),car.Platform.Position+Vector3.new(7,8,7))
        for i, p in pairs(workspace:FindPartsInRegion3(r3,script.Parent,math.huge)) do
            local pl = game.Players:GetPlayerFromCharacter(p.Parent)
            if (pl ~= nil) then
                table.insert(plist,pl)
            else
                table.remove(plist, #plist)
            end
        end 
    end
end)

But it doesn't seem to work. How can i fix this?

1 answer

Log in to vote
0
Answered by
A_Mp5 222 Moderation Voter
3 years ago

table.remove takes instance number value placement in a table, and not instance direcxtly.

spawn(function()
    while wait() do
        local r3 = Region3.new(car.Platform.Position-Vector3.new(7,0,7),car.Platform.Position+Vector3.new(7,8,7))
        for i, p in pairs(workspace:FindPartsInRegion3(r3,script.Parent,math.huge)) do
            local pl = game.Players:GetPlayerFromCharacter(p.Parent)
            if (pl ~= nil) then
                table.insert(plist,pl)
            else
                table.remove(plist, i)
            end
        end 
    end
end)
Ad

Answer this question