Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.