Item repeating it self even though im removing it from table

So with the script I have, Im in theory removing the selected item from a table which means it can’t be chosen again but its being chosen again.

local function chooseLoc(Location)
	local locations = {
		"Loc1",
		"Loc2",
		"Loc3",
		"Loc4",
	}

	local index = math.random(#locations)
	local gender = locations[index]
	table.remove(locations,index)

	

	return gender

end


local function SpawnCustomer()
	if Capacity.Value >= 1 then
		
		local currentCustomer = Customers:Clone()
		currentCustomer.ChosenFood.Value = chooseItem()
		local Path = SimplePath.new(currentCustomer)
		local loca = chooseLoc()
		print(loca)

		print(chooseItem())
		currentCustomer.Parent = game.Workspace
		currentCustomer:WaitForChild("HumanoidRootPart").CFrame = game.Workspace.CustomerSpawners.Spawn1.CFrame
		Capacity.Value = Capacity.Value - 1
		Path:Run(game.Workspace[loca])
		
		Path.Blocked:Connect(function()
			Path:Run(game.Workspace[loca])
		end)
		Path.Error:Connect(function(errorType)
			Path:Run(game.Workspace[loca])
		end)
		
		
	end
end

Thanks

1 Like

Never Mind turns out the table had to be outside the function

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.